Solving series differential equation use ode45

조회 수: 1 (최근 30일)
Abert
Abert 2020년 2월 25일
댓글: Star Strider 2020년 2월 26일
i need to solve the following equations in matlab:
and my codes looks like this :
%initial condition
y0=[0;0;0];
%calling ode function
BO=[0.1 0.2 0.3 0.5 0.8 1 1.5 2];
for i=1:8
bo=BO(i);
[s,y]=ode45(@(s,y) lapalce(s,y,bo),[0 3],y0);
plot(s,y(1));
hold on
end
function dydt=lapalce(s,y,bo)
dydt=[2-bo*y(2)-((sin(y(1))/y(3)));
sin(y(1));
cos(y(1))];
end
matlab is giving me answers like
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
can anyone tell me what went wrong?

채택된 답변

Star Strider
Star Strider 2020년 2월 25일
Yes!
The problem is:
y0=[0;0;0];
so:
sin(y(1))/y(3)
will be NaN because sin(0)=0, and 0/0 (and Inf/Inf) result in NaN values.
Settimg ‘y0’ to very small values instead:
y0=[0;0;0]+1E-12;
may give you useful output.
  댓글 수: 2
Abert
Abert 2020년 2월 26일
thank you, i am getting some results now, though it is different than what i thought to be. Need to check my equations.
Star Strider
Star Strider 2020년 2월 26일
As always, my pleasure!
Having all zero initial conditions (or initial estimates in other contexts and applications) is likely not the best approach.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by