ODE matlab, handling variables
Ältere Kommentare anzeigen
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
Weitere Antworten (0)
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!