ODE15s time vector size

조회 수: 2 (최근 30일)
Lukasz Dziechciarczyk
Lukasz Dziechciarczyk 2018년 3월 15일
답변: Lukasz Dziechciarczyk 2018년 3월 15일
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

채택된 답변

Jan
Jan 2018년 3월 15일
편집: Jan 2018년 3월 15일
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.

추가 답변 (2개)

Torsten
Torsten 2018년 3월 15일
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
Lukasz Dziechciarczyk
Lukasz Dziechciarczyk 2018년 3월 15일
Not sure I understand you. What's the physical meaning of time span with for example three values?
Star Strider
Star Strider 2018년 3월 15일
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
Lukasz Dziechciarczyk 2018년 3월 15일
Thank you very much! Awesome :)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by