Effacer les filtres
Effacer les filtres

Saving the derivative during solving ode functions

1 vue (au cours des 30 derniers jours)
Hiep Dang
Hiep Dang le 11 Déc 2012
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,

Réponse acceptée

Hiep Dang
Hiep Dang le 11 Déc 2012
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.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 11 Déc 2012
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.

Community Treasure Hunt

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

Start Hunting!

Translated by