ODE15s time vector size
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lukasz Dziechciarczyk
el 15 de Mzo. de 2018
Respondida: Lukasz Dziechciarczyk
el 15 de Mzo. de 2018
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
0 comentarios
Respuesta aceptada
Jan
el 15 de Mzo. de 2018
Editada: Jan
el 15 de Mzo. de 2018
A tspan with 3 values has exactly the same physical meaning as with 2 values:
tspan1 = [t1, t3]
tspan2 = [t1, t2, t3]
For both tspan the integration runs from t1 to t3, but for tspan1 the trajectory is replied for each computed time step, where the step size controller determines the output times, while for tspan2 the trajectory is replied for exactly the times t1, t2, t3.
This is useful, if you need the trajectory to specific intermediate steps, e.g. for a fixed frame rate in a 3D animation.
For your problem, you can use:
tspan = linspace(0, 3e-6, 100);
to get the trajectory for 100 time points.
0 comentarios
Más respuestas (2)
Torsten
el 15 de Mzo. de 2018
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 comentarios
Star Strider
el 15 de Mzo. de 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.
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!