Problem with ordinary differential equation

1 visualización (últimos 30 días)
Fatemeh
Fatemeh el 22 de Abr. de 2023
Comentada: Fatemeh el 23 de Abr. de 2023
Hello, can anyone clarify me why I'm getting a line chart with the following code and how can I fix that? My initial conditions are y(C0)=t0, and y'(C0)=0. Thanks
syms y(x) x Y
N=5;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
C0=1;
C=5;
t0= (((1-a)/a)*N^(a+b))/(r-m);
Dy = diff(y);
D2y = diff(y,2);
ode = y-((((1-a)/a)*N^(a+b))-x*m*Dy+0.5*D2y*(x^2)*(s^2))/(r-m);
[VF,Subs] = odeToVectorField(ode);
odefcn = matlabFunction(VF, 'Vars',{x,Y});
tspan = [C0 80];
ic = [t0 0];
[x1,y1] = ode45(odefcn, tspan, ic);
figure
plot(x1,y1(:,1), 'DisplayName','(x_1,y_1_1)')
grid

Respuesta aceptada

Star Strider
Star Strider el 22 de Abr. de 2023
The initial condition of 0 for keeps it 0 througuout the integration.
syms y(x) x Y
N=5;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
C0=1;
C=5;
t0= (((1-a)/a)*N^(a+b))/(r-m)
t0 = 167.7051
Dy = diff(y);
D2y = diff(y,2);
ode = y-((((1-a)/a)*N^(a+b))-x*m*Dy+0.5*D2y*(x^2)*(s^2))/(r-m);
[VF,Subs] = odeToVectorField(ode)
VF = 
Subs = 
odefcn = matlabFunction(VF, 'Vars',{x,Y})
odefcn = function_handle with value:
@(x,Y)[Y(2);(1.0./x.^2.*(sqrt(5.0).*-3.0e+2+x.*Y(2)+Y(1).*4.0))./5.0e+1]
tspan = [C0 80];
ic = [t0 0];
[x1,y1] = ode45(odefcn, tspan, ic);
figure
plot(x1,y1(:,1), 'DisplayName','(x_1,y_1_1)')
grid
.
  4 comentarios
Star Strider
Star Strider el 23 de Abr. de 2023
@Fatemeh — As always, my pleasure!
@Torsten — Thank you!
(I just now saw this.)
Fatemeh
Fatemeh el 23 de Abr. de 2023
Thanks so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by