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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by