ode45 returns NAN, HOW could I modify it?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (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
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!