Solving system of coupled ode using ode45
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 18 Oct 2021
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!