Getting data from inside ode15s solver
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brandon
am 30 Jan. 2020
Kommentiert: Star Strider
am 31 Jan. 2020
I am using ode15s to solve a differential equation in a combustion particle system. The problem that I have is that the ode_func that I am putting in ode15s has some data inside of it that I want to get outsie of the function. This data is not the output of the ode_func, so it's not saved as output. My question is how is the best way to get it out? Should I use a global variable inside the ode_func that updates it's value while it solves, then I can access it outside of the func? Or is it possible to add another output to the ode_func? I'm not sure how the ode15s would handle multiple outputs from the ode_func.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 30 Jan. 2020
Do not use global variables!
Write one version of your ODE function that ode45 (or whatever solver you are using) then solves.
Then in a for loop, use those independent and dependent variable arrays with a second version of your ODE function that uses the solved values for the independent and dependent varialbles and instead returns the varialbles you are interested in in each iteration of the loop.
That has worked for me in the past, and it is likely more efficient than any other option.
4 Kommentare
Star Strider
am 31 Jan. 2020
The for loop is essentially the only way to get the step-by-step data for the other variables, because of the way ODE functions are written. (They are intended to be evaluated step-wise.) At each iteration of the for loop, calculate the desired variables with the specific values of the integrated independent and dependent variables and return the other variables as an output of the slightly revised ODE function.
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!