ODE - Save variables for every time step
25 ビュー (過去 30 日間)
古いコメントを表示
Hello Guys,
I am stuck with saving time dependent variables inside a model function ... I was browing some already answered questions but none seems to help.
I have the following:
[t, f_val] = ode15s(@model,tspan,yeq);
That yields my f_val as a function of time.
But inside my model function I have also yy variable (time dependent) I would like to trace
function [f, yy] = model(t,yeq)
f= ... %some expression
yy= ... %some expression
How can I extract yy as a function of time?
Cordially
0 件のコメント
回答 (2 件)
Bjorn Gustavsson
2021 年 3 月 8 日
This is something that is (simplest?) done by calculating the second output once after you've integrated the ODE-system. Either in one fell swoop if your ODE-function can handle arrays for input of t and f:
[f_second_time_around_or_tilde, yy] = model(t,f_val);
Or you can quickly loop over t:
for i_t = numel(t):-1:1,
yy(i_t,:) = model(t(i_t),f_val(i_t,:));
end
Since the odeNN-functions take cunningly adaptive steps in time we cannot trivially save all the values of yy along the steps...
HTH
3 件のコメント
Bjorn Gustavsson
2021 年 3 月 8 日
What with the second loop-based suggestion? That explicitly calculates yy for every step in the solution you have...
sko
2021 年 4 月 22 日
10 件のコメント
Bjorn Gustavsson
2021 年 4 月 22 日
Yes, the in solution I provided I couldn't now what the dimensions of your additional outputs were expected to be, therefore I opted to provide something that you could easily adjust to match the dimensions of your outputs (one or the other parameter might even have different dimensions at different time-steps as far as I could see...).
参考
カテゴリ
Help Center および File Exchange で Equation Solving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!