Why do I get undefined variable error in the attached code?

<<
>>
What's wrong with my code? I can't figure it out, I'm a beginner. Please help.
See screenshots attached. I'm trying to plot and show that the system is non linear.
The error says "undefined Cw1"

3 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2017 年 9 月 9 日
here Cw1 and Cw2 are not in input data within the function, then how you assigned x(1)=Cw1.. ..so on, So either you have to consider Cw1, Cw2 as input during function call or it should be defined before assigned as x(1)=Cw1.
OCDER
OCDER 2017 年 9 月 9 日
Did you mean to say this?
Cw1 = x(1);
Cw2 = x(2);
Otherwise, no inputs will affect the output xdot.
dpb
dpb 2017 年 9 月 9 日
In future, paste actual code text, not figure. That way folks can edit directly rather than having to type everything from scratch.

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2017 年 9 月 9 日
編集済み: dpb 2017 年 9 月 9 日

0 投票

As another wrote, looks like you transposed the LH and RH sides of the assignment of input argument x to local variables. Why not use the named variable dummy argument array internally as the local variable and Matlab array syntax as well?
function Cwdot=NonLin(t,Cw)
Cwi=1;
k=1.5;
F=100;
V=[400; 2000];
Cw=Cw(:); % ensure column vector
Cwdot=F./V.*(Cwi-Cw)-k*Cw.^2;
end

カテゴリ

質問済み:

2017 年 9 月 9 日

編集済み:

dpb
2017 年 9 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by