Solving system of coupled ode using ode45
조회 수: 2 (최근 30일)
이전 댓글 표시
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])
댓글 수: 0
답변 (1개)
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')
.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!