ODE15s time vector size
Show older comments
Hi everyone,
I am using an ode15s solver to solve some coupled equations and I put this into a for loop and for each iteration I solve the same equations but changing one parameter that goes into the equation (it's a constant). Now what I am seeing is that each time ode is giving me results, the time vector has a different size and I can't then put all of that into one matrix, since the resulting vectors are all different size. Is there a way around it? I am ok if the matrix would be of certain size to fit the longest time vector and the shorter vectors would have zeros added i.e.
So what I am doing:
for i=1:length(pump_barrel)
t_span = [0 3e-6]; % time-span
i_values = [0.9 0 0.1 0 0]; % initial values. [0 0 0] should be ok
tol = 0.0000000000001;
options = odeset('RelTol',tol,'AbsTol',[tol tol tol tol tol]);
[t,y] = ode15s(@(t,y) NV(t,y,argins),t_span,i_values,options); % calling the ode-solver
PL=y(:,2)+y(:,4);
disp(length(t))
PL_time(:,i)=y(:,2)+y(:,4); % here is a problem, first vector goes into the PL_time matrix, but the second is larger and throws error
end % end of the for loop in which I am changing a parameter in argins
Accepted Answer
More Answers (2)
Torsten
on 15 Mar 2018
0 votes
If t_span has more than two elements, the ode integrator will output the solution at exactly the specified time instants.
Best wishes
Torsten.
2 Comments
Lukasz Dziechciarczyk
on 15 Mar 2018
Star Strider
on 15 Mar 2018
With more than two values, the ODE solvers will output its results at times closely corresponding to the times in the vector. For three values, it would output a three-row time vector (in your code, ‘t’), and a three-row vector or matrix of the ‘y’ values.
Lukasz Dziechciarczyk
on 15 Mar 2018
0 votes
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!