simulink error

3 次查看(过去 30 天)
Cosmin Darab
Cosmin Darab 2011-9-29
Hi, I have a simulink error : "Error in 'model/S-Function' while executing MATLAB S-function 'polinomf', flag = 1 (derivatives), at time 0.0." and do not know anythink about it. Can someone help me? This is the code:
function [sys, x0] = simulink(t,x,u,flag)
if flag == 0
sys = [1 0 1 2 0 0];
x0 = [1];
TS = [-1 0];
elseif flag == 1
Ka=10^-4.75;
Kw=10^-14;
w=Xb-Xa;
w1=Ka*w;
z=-Kw*Ka;
y=w1-Kw;
x=Ka+Xb;
p=[1 x y z];
n=roots(p);
if n(1)>0 r=n(1);
else if n(2)>0 r=n(2);
else r=n(3);
end
end
ph=-log10(r);
pH=ph';
sys = pH;
elseif flag == 3
sys = x;
else
sys = [];
end
Thank you

采纳的回答

Walter Roberson
Walter Roberson 2011-9-29
In the case where flag == 1, your code calculates
w=Xb-Xa;
but neither Xb nor Xa are defined. This causes MATLAB to error() out.
You do use w, so you will have to figure out how to set Xb and Xa.
  2 个评论
Cosmin Darab
Cosmin Darab 2011-9-29
thank you for answer
is it not ok that Xb and Xa are defined in workspace?
Walter Roberson
Walter Roberson 2011-9-29
Every function has its own workspace. Xa and Xb have not been defined in the workspace of the function.
If the values were defined before the simulation in the base workspace, and either you have used a "From Workspace" block to get them in to the simulation (and do not change them) or you do not otherwise use them in the simulation, then you can import the value you need from the base workspace using
w = evalin('base','Xb - Xa');
However, if you _are_ importing them in to Simulink from the base workspace, or if you calculate them in Simulink or if you modify them in Simulink, then it would be better to connect those values to become inputs to the S function.

请先登录,再进行评论。

更多回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-9-29
Why do you define your function as "simulink"? It sounds like you are using the Simulink toolbox if you are talking about S-function. Should it cause confusion or even problem?

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by