How can I update initial guess for Newtons algorithm inside a ODE45 function for the next step?

I need to solve 5 differential equations, but first I need to solve a nonlinear equation with Newton's algorithm to find some of the variables used on ODEs. Here is my function; I am not writing the whole code, its long and complicated, but I guess this will help you to understand my solution.
______________________________________________________________________________________________ function dxdf = retentatepurityC2(f,x,r,qA, qB, qC, qD, qE)
%defining the tolerance for Newtons Algorithm t=10e-15;
%initial value of yPa (this is what I want to update in the next step by using the value from previous step.) yPa=....
% the loop for Newton's Algorithm The loop calculates the value of yPa for given x(1), x(2), x(3) and x(4). After yPa is calculated the variables used in ODEs below are calculated (like y1, y2 ...etc)
%solving differential equations
there are five diff. equations dependent on y1, y2 ...etc. dxdf(1,1)= dxdf(2,1)= dxdf(3,1)= dxdf(4,1)= dxdf(5,1)=
end
When the calculations end for a time step, ODe starts from the beginning and uses the yPa that is defined for the very first step. I need to update yPa.
________________________________________________________________________________________
I need to update the initial value of yPa for the next f increment in the code. If I dont do it, the Newtons algorithm does not converge since the initial value is not good. How can i update my initial guess for Newton's Algorithm (yPa(n)) in the code for the next increment. The next yPa should be equal to y1 from previous step.
Thanks, Merve

 Risposta accettata

Don't solve for yPa the way you do.
Include the algebraic equation for yPa in the system of ODEs. The result is a system of DAEs (a mixture of algebraic and ordinary differential equations). ODE15s can handle DAEs by defining the mass matrix appropriately.
For an example, take a look at the Robertson problem under
Best wishes
Torsten.

2 Commenti

Thank you very much, Torsten, your answer helped me indeed.Now I am able to update the initial guess for each iteration.
But by including the algebraic equation in the overall system of equations, it is no longer necessary to update the initial guess. You can directly take the value of the ODE solver for the algebraic variable.
Best wishes
Torsten.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by