How to revise the program?

【m.file】ODE45_fun:
function dx=ODE45_fun(t,x)
a1=1;a2=1;e1=9;e2=7;f1=56;f2=98;g1=76;g2=665;
a=a1+a2;
e=e1+e2;
f=f1+f2;
g=g1+g2;
dx(1)=x(3)+x(2)-x(4)*x(2)+2*x(5)*x(2)+x(2)*x(2)+x(5)+e+f+g;
dx(2)=x(1)+x(3)-x(4)*x(2)+x(2)*x(2)+x(5)*x(5)+x(5)*x(2)+e*f+g;
dx(3)=x(2)+x(1)-x(5)*x(1)+x(4)*x(3)-x(3)-x(4)-e*g-f;
x(6)=x(4)*x(5)+x(2)*x(3)+e*f+e*g;
dx(4)=x(5)*a-x(3)*x(1)-x(3)-e*f*g*x(6)
dx(5)=x(4)*a-x(2)*x(1)+e*f*x(1)+x(2)*x(2)*x(5)+x(2)*x(5)*x(5)+e*f+f*g
dx=[dx(1);dx(2);dx(3);dx(4);dx(5);dx(6)];
【m.file】DE45_main:
tspan=[0,10];
x0=[0:0.1:2:0:0.1:2];
[t,x]=ode45('ODE45_fun',tspan,x0);
data=[t,x];
save ODE45_data.txt data-ascii
subplot(2,3,1),plot(t,x(1))
subplot(2,3,2),plot(t,x(2))
subplot(2,3,3),plot(t,x(3))
subplot(2,3,4),plot(t,x(4))
subplot(2,3,5),plot(t,x(5))
subplot(2,3,6),plot(t,x(6))
MATLAB:
>> ODE45_main
Warning: Colon operands must be real scalars.
Warning: Colon operands must be real scalars.
??? Error using ==> funfun\private\odearguments
No default parameters in ODE45_FUN. Use ode45(ODE45_FUN,tspan,y0,...) instead.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> ODE45_main at 3
[t,x]=ode45('ODE45_fun',tspan,x0);

 採用された回答

Guillaume
Guillaume 2015 年 3 月 13 日

1 投票

What is
x0=[0:0.1:2:0:0.1:2];
supposed to mean? On my version of matlab (2015a) it does not give me any warning but it creates an empty vector.
I suspect it's the cause of the warning and ultimately the cause of the error since you're passing empty for the initial condition.
See colon for documention about the syntax of :

5 件のコメント

Lan
Lan 2015 年 3 月 14 日
x0=[0:0.1:2:0:0.1:2];
revise: x0=[0;0.1;2;0;0.1;2]; ?
Lan
Lan 2015 年 3 月 15 日
Lan
Lan 2015 年 3 月 15 日
How can i avoid the empty vector?
Guillaume
Guillaume 2015 年 3 月 16 日
The initial condition is usually specified as a row vector, so possibly you meant:
x0 = [0 0.1 2 0 0.1 2];
Similarly the function you integrate must return a column vector, so possibly you meant:
dx = [dx(1) dx(2) dx(3) dx(4) dx(5) dx(6)];
This is still not going to work though, since you haven't defined dx(6).
Lan
Lan 2015 年 3 月 17 日
thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

タグが未入力です。

質問済み:

Lan
2015 年 3 月 13 日

コメント済み:

Lan
2015 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by