Use ode values without storing
古いコメントを表示
Hi, I have a system of ODEs that I can solve using ode23. To solve I do:
[t, S] = ode23(@odefunc,tSpan,S0)
and then what I am really interested in is a variable:
D(t) = 2*pi*(S(1)(t) + S(2)(t) + S(3)(t) + ...)
and then I plot D(t) vs t.
Doing it this way, however, I am forced to store all S(1)(t), all S(2)(t), etc. when I really only need their sum for each time. This takes a lot of memory since I have 280k*3 equations. How can I go about just calculating D at each step and saving that in an array to then plot D(t) vs t.
採用された回答
その他の回答 (1 件)
Jacob Ward
2017 年 9 月 6 日
You could create a function that calls ode23, finds the sum of S, and then returns that sum. Something like this:
function [t,D] = odeSum()
...
[t, S] = ode23(@odefunc,tSpan,S0)
D(t) = 2*pi*(S(1)(t) + S(2)(t) + S(3)(t) + ...)
end
Since the function throws away any variables that aren't output variables, you wouldn't be saving all the useless S data and would be left with only D when you come out of the function.
3 件のコメント
olabaz
2017 年 9 月 6 日
Jacob Ward
2017 年 9 月 6 日
I see. Well, I could be wrong, but I think in order to do what you are saying you'd have to go in and change the ode23 code itself so that it only outputs what you want. Maybe someone else will have a better suggestion.
Stephen23
2017 年 9 月 7 日
"...you'd have to go in and change the ode23 code itself..."
Not required at all. See my answer.
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!