Updating variables within ODE function

5 views (last 30 days)
Nishant Kumar
Nishant Kumar on 12 Aug 2016
Commented: Torsten on 12 Aug 2016
I want to update the values 'k0g,w0g,V0g' within the ODE function 'eval_dpardtau'.
Function call:
[tau,par] = ode45(@(tau,par) eval_dpardtau(tau,par,options,k0g,w0g,V0g),tauspan,par0);
Inside ODE function 'eval_dpardtau':
[k_0g,w_0g,V_0g] = eval_saddle_track(options,k0g,w0g,V0g);
Basically, I am using an iterative method ( fsolve) inside the function 'eval_saddle_track' for which I use the guess values 'k0g,w0g,V0g' to obtain the 'k_0g,w_0g,V_0g' values. After each time step (step in 'tau'), I want
k0g = k_0g;
w0g = w_0g;
V0g = V_0g;
so that at the next step, the iterative search in function 'eval_saddle_track' takes the updated guess value from the previous step, and NOT the initial value I pass with the call to 'ode45'.
I searched on the forum for a solution but could not find any. How can I pass the updated values of 'k0g,w0g,V0g' to 'eval_saddle_track'?
Thanks in advance.
EDIT#1: The values in structure 'options' are updated with the calculated value of 'par'.

Answers (1)

Torsten
Torsten on 12 Aug 2016
ode45 can also solve for algebraic variables like k0g,w0g and V0g. So instead of iterating with fsolve, add the algebraic equations for k0g, w0g and V0g to the system to be solved by ode45 by using the mass-matrix option of the ODE solver.
Best wishes
Torsten.
  2 Comments
Nishant Kumar
Nishant Kumar on 12 Aug 2016
But the calculation for 'k0g,w0g,V0g' is not through algebraic relations. That is why I have to use 'fsolve' in the first place. I have not used the mass-matrix option before but I will take a look into it whether I can use it for my case.
Thanks.
Torsten
Torsten on 12 Aug 2016
But fsolve solves systems of algebraic equations, and these equations can be solved by ode45 together with the ordinary differential equations.
Best wishes
Torsten.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!