Saving the derivative during solving ode functions
显示 更早的评论
I have a question and hope that somebody came across this earlier. Your advice will be of great help. I have to solve a set of differential equations. They are coupled altogether, and look like this:
dw(1) = f(w(1),w(2),dw(2));
dw(2) = g(w(1),w(2),dw(1));
I don't want to get into details of f and g since they're quite long. The solution can be generated. However, besides w(1) and w(2) as the outputs, I also want to get dw(1) or dw(2), Is there anyway that I can use to achieve this. For some reasons, calculating the derivatives of w(1) and w(2) (after getting the outputs) is not desirable for this problem. What I want is somehow saving dw(1) and dw(2) in every time instant.
Thanks a lot for your help,
采纳的回答
更多回答(1 个)
Walter Roberson
2012-12-11
0 个投票
You could use an options structure with an OutputFcn specified. Exactly how you do the saving depends on what is convenient. For example, you could use a "global" cell array.
Note: time steps do not always go strictly forward. Sometimes, especially near boundary conditions, the ode solvers need to step backwards for greater accuracy.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!