How to output matlab ode dependent variable at same time step as T and Y?
1 回表示 (過去 30 日間)
古いコメントを表示
I am using ode15s to solve a coupled ode functions, like
[T Y]=ode15s(@ydot, [1:100],y0,options)
function ydot=odefunction(t,y)
dept1=f(y(1),y(2));
ydot(1)=dept1*y(1)*y(2)
ydot(2)=a*y(1)+c*y(2)
end
Now I have output file with T and Y from t=1 to t=100 with interval of 1. Right now I am using global variable and output "dept1" at every time step odesolver called, like t=[...7.7241 7.8241 8.6241 9.6854 10.524...]. Question is how could I output dependent variable like "dept1" from t=1 to t=100 with interval of 1?
0 件のコメント
回答 (2 件)
Richard Brown
2012 年 7 月 2 日
編集済み: Richard Brown
2012 年 7 月 2 日
By far the best way is to compute your dependent variable afterwards with the y matrix that was computed by the ODE solver. No messy code (or globals / persistents) required, and it probably won't add a huge amount (proportionally) to your computational cost.
0 件のコメント
Walter Roberson
2012 年 7 月 2 日
編集済み: Walter Roberson
2012 年 7 月 2 日
You might still need to use a global variable, but you can get it to output only at the locations you specify in tspan.
Use odeset() to construct an options structure that includes an OutputFcn property. See http://www.mathworks.com/help/techdoc/ref/odeset.html#f92-1016858 for the parameters of the function that will be called.
I'm thinking: use the init flag to initialize a persistent variable to []; use the calls with no flags to append to the persistent; use the done flag to transfer data out of the persistent (possibly by setting a global.)
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!