How to apply an ODE Solver to a while loop with non equivalent step size?
Ältere Kommentare anzeigen
Hello there!
I've got this, probably very basic, problem but couldn't find any solution on the internet so far. I've got a set of ODEs, which I am solving with an ODE Solver (ode15s).
To solve the one main ODE, I need the current values of another equation. Therefore I implemented a main routine with function handles. After it got all the values, it proceeds to the next time step. This is realised with a for loop and fixed step size. The function handles take the values they need for the certain time step, solve the ODE, and give the value of the next time step back to the mother routine.
It looks in principal like this (without the code of the function handles):
t0 = 0;
tend = 2.5;
ntime = 5000;
dt = (tend-t0)/ntime;
t = t0 : dt : tend;
...then some parameters and the initial conditions are set, mostly as zero vectors with the size t:
R = zeros(1,size(t,2));
dRdt = zeros(1,size(t,2));
pg = zeros(1,size(t,2));
We = 1.375;
pv = 2.339;
...
R(1) = 1 ;
dRdt(1) = 0;
pinf (1) = p_inf_handle(0);
pg(1) = p_inf_handle(0)+ 2/(We*R(1)) - pv;
...
and then, the main loop looks basically like this:
for i=2:dt:size(t,2)
pg(i) = pg(i-1);
pinf(i) = p_inf_handle( t(i) );
delta_pg = 1;
tcurrent = t(i)
%solving the R values of step i
[R(i),dRdt(i)] = rpe_handler ...
( t(i) , dt , R(i-1) , dRdt(i-1) , pg(i) , ...
m_flux , dm_flux , rpe_parameters,pinf(i));
%solving the pg values of step i
pg(i) = pg(1) * Ng(1) / Ng(1) * ( R(1) / R(i) )^3;
end
My request is the following: I want to solve the same problem with a while loop and different step sizes in the mother routine. Is that possible or is that not possible for the ODE solvers? I know, that ode15s itself works with adaptive step size, but that doesnt matter in this case.
I left some parts of the code out, but I hope it is enough to clarify the problem.
Your help is very much appreciated!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!