Solving system of coupled ode using ode45

2 visualizaciones (últimos 30 días)
Zhijian Zhou
Zhijian Zhou el 18 de Oct. de 2021
Respondida: Star Strider el 18 de Oct. de 2021
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])

Respuestas (1)

Star Strider
Star Strider el 18 de Oct. de 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')
.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by