ode45 returns NAN, HOW could I modify it?
古いコメントを表示
clear
clc
[t,x]=ode45(@eqns,[0.1:0.2:100],[10;0.01;100;-0.0225;10;-0.01]);
for i=1:6
plot(t,x(:,i))
hold on
end
function dxdt = eqns(t,x) % function definition
m=9.0807;
v1=6;
v2=150;
rc=1;
dxdt = [x(2);
2*v1*x(4)+v2*x(3)+v1^2*x(1)-(m*(rc+x(1)))/(((rc+x(1))^2+(x(3))^2+(x(5))^2)^1.5)+(m/rc^2);
x(4);
2*v1*x(2)-v2*x(1)+(v1^2)*x(3)-m*x(3)/(((rc+x(1))^2+x(3)^2+x(5)^2)^1.5);
x(6);
(-m*x(5))/(((rc+x(1))^2+x(3)^2+x(5)^2)^1.5);]
end
回答 (2 件)
madhan ravi
2018 年 12 月 25 日
編集済み: madhan ravi
2018 年 12 月 25 日
Reduce the time span and increase time steps (or don't put any time step let matlab assume it) for instance from 0 to 1 -> [0 1] .
Add figure before plot(...) and remove hold on so that each solution can be viewed nicely.
[t,x]=ode45(@eqns,[0 10],[10;0.01;100;-0.0225;10;-0.01]); % change to this
% ^^----example
for i=1:6
figure % add this
plot(t,x(:,i))
% hold on %% remove this
end
Star Strider
2018 年 12 月 25 日
After about ‘t=60’, your differential equation saturates (becomes greater than realmax (link)), and subsequent values are NaN. You need to examine your differential equations to be certain that you have coded them correctly, and that the constants are correct.
Take a look at a higher-resolution version of the output of your system:
tspan = linspace(0, 10, 5000);
[t,x]=ode45(@eqns,tspan,[10;0.01;100;-0.0225;10;-0.01]);
semilogy(t,abs(x))
That could give you some idea of where the problems are.
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!