Solving system of coupled ode using ode45

조회 수: 2 (최근 30일)
Zhijian Zhou
Zhijian Zhou 2021년 10월 18일
답변: Star Strider 2021년 10월 18일
where Bo is just a constant and z' s' r' φ are just variables
I was trying to solve this system of coupled ode using ode 45. The following is the code I currently have but the xsol returns NaN. I would greatly appreciate any thoughts on how to fix the problem.
f = @(s,x) [2+2*x(2)-sin(x(1))/x(3); sin(x(1)); cos(x(1))]; %I set B0 = 2 just as a place holder
[s xsol] = ode45(f,[0,10],[0 0 0])

답변 (1개)

Star Strider
Star Strider 2021년 10월 18일
The NaN values are the result of the initial conditions all being 0. With a bit of cheating (setting the initial conditions all to eps instead) it works —
f = @(s,x) [2+2*x(2)-sin(x(1))/x(3); sin(x(1)); cos(x(1))]; %I set B0 = 2 just as a place holder
[s xsol] = ode45(f,[0,10],[0 0 0]+eps);
figure
plot(s, xsol)
grid
figure
yyaxis left
plot(s, xsol(:,1))
yyaxis right
plot(s, xsol(:,2:end))
grid
legend('x_1','x_2','x_3', 'Location','best')
.

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by