Saving the derivative during solving ode functions

1 次查看(过去 30 天)
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,

采纳的回答

Hiep Dang
Hiep Dang 2012-12-11
Thanks Walter for your answer. However, I don't understand much about your recommendation.
It will involve with a "for" loop to call the dw after getting the output of t and w. It works for me at the moment, but will not be efficient because of the loop, especially when the ode function system is complicated.

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-12-11
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.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by