ODE matlab, handling variables
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Juan David Gamba Camacho
am 19 Nov. 2019
Kommentiert: Juan David Gamba Camacho
am 20 Nov. 2019
Hello,
I'm trying to change a variable once every integration step using Matlab's ODE solver (ode45).
[yd,k] = my_func(t,y,k)
a = func_a(k,y);
b = func_b(k,y);
k = b*a;
end
where k is initialized to be zero.
k=0;
[T,Z] = ode45( @my_func, [0 0.3], INITIAL_COND, options,k)
But, in this way the value of k doesn't change out of the function "py_func" (k is always read as zero), using Persistent and Global options will not solve the problem either because the integrator may evaluate the function many times before taking a certain step. Also persistent and global functionalities seem to slow-down the integration.
Does anyone know any other way for doing this implementation?
Thanks
1 Kommentar
Steven Lord
am 19 Nov. 2019
Can you show us the mathematical form of the ODEs you're trying to solve? This approach of changing k sounds like it would be problematic when the ODE solver needs to reject a step and take a smaller step from the previous location. I want to understand the underlying problem, as that may help us offer a more robust solution.
Akzeptierte Antwort
James Tursa
am 19 Nov. 2019
You can't do this if the derivative yd depends on k. The ode solvers need to have consistency when calling the derivative function. E.g. the solvers might call your derivative function for a previous time when changing a step size internally, or they might even call your derivative function at the same point more than once. You have no control over this as it all happens in the background while the solvers try to keep the estimated errors within tolerances. If you suddenly change the parameters of the derivative function you effectively pull the rug out from under the ode solver and will confuse it greatly. You will either send it into a condition where it simply quits on you, or worse will simply give you a garbage answer. Changing the parameters of the derivative function during integration sounds like you really don't have an ODE to solve. Can you explain in more detail what you are trying to do and why?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!