Solving with ode45 with a solution dependant variable in the ode
Hi,
Let’s say I want to solve :
with , with all following the same ode as y(z).
I can theoretically solve each ode with RK4 at step z+dz and then calculate N(z+dz). But how do I do it using the already implemented RK4 function implemented in Matlab? Would something like this work or is there a way better solution?
while(z<zLim)%%This is just an idea of the algorithm I would use
zspan=[0 dz];%Solving the ODE for a very small zspan
if(z~=0)
y0=y(length(y));
else
y0=0;
end
[z,y] = ode45(@(z,y) N*y, zspan, y0);
%Calculate c(z),g(z),….
%Calculate N at step dz
z=z+dz;
end
ThanksHi,
Let’s say I want to solve :
with , with all following the same ode as y(z).
I can theoretically solve each ode with RK4 at step z+dz and then calculate N(z+dz). But how do I do it using the already implemented RK4 function implemented in Matlab? Would something like this work or is there a way better solution?
while(z<zLim)%%This is just an idea of the algorithm I would use
zspan=[0 dz];%Solving the ODE for a very small zspan
if(z~=0)
y0=y(length(y));
else
y0=0;
end
[z,y] = ode45(@(z,y) N*y, zspan, y0);
%Calculate c(z),g(z),….
%Calculate N at step dz
z=z+dz;
end
Thanks Hi,
Let’s say I want to solve :
with , with all following the same ode as y(z).
I can theoretically solve each ode with RK4 at step z+dz and then calculate N(z+dz). But how do I do it using the already implemented RK4 function implemented in Matlab? Would something like this work or is there a way better solution?
while(z<zLim)%%This is just an idea of the algorithm I would use
zspan=[0 dz];%Solving the ODE for a very small zspan
if(z~=0)
y0=y(length(y));
else
y0=0;
end
[z,y] = ode45(@(z,y) N*y, zspan, y0);
%Calculate c(z),g(z),….
%Calculate N at step dz
z=z+dz;
end
Thanks ode45, ode MATLAB Answers — New Questions