Problem with ordinary differential equation
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 22 Apr 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)
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
.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!