Solving system of coupled ode using ode45
显示 更早的评论
where Bo is just a constant and z' s' r' φ are just variablesI 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 个)
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')
.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

