How can I use generated time vector in the main program in subprogram ?

1 visualización (últimos 30 días)
Hello,
I have a problem using the ode45 solver, namely, with a time step.
I have the main program, in which using an ode45 solver I solve a system of differential equations, defined in another subprogram.
In the subprogram I need to use in my equations time step (dt) generated by ode45, however, when I define variable 't' in the subprogram, Matlab see it as a scalar, not a vector, and does not use dt (derivative of time), but the specific time. So my question is, it is possible to call the time vector in the subprogram and use a derivative of time to indirectly calculate the system of ODE?
I hope that it is clear for you. Please, if you have any idea how I can fix it, write me :)
  3 comentarios
Paulina Wienchol
Paulina Wienchol el 8 de Oct. de 2021
Thanks for answer! Ok, so how can I deal with it? I thought about setting fixed time step, but it is possible using ode45? What do you think? Below, I showed the piece of my code. If you have further questions, please ask :)
Steven Lord
Steven Lord el 8 de Oct. de 2021
The code is useful to see, but it shows how you think the problem that you're trying to solve should be solved. It doesn't show us the actual problem that you're trying to solve, so we can't tell how well what you've written matches what you want to do. As an analogy:
  • If you hand me a plate of delicious cookies and you were trying to bake cookies, you've succeeded.
  • If you hand me that same plate of cookies but you were trying to bake an apple pie, you haven't succeeded.
So now that you've shown us your plate of cookies (your code), show us the mathematical equations that you're trying to solve, like so we can tell what you were trying to bake.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 8 de Oct. de 2021
I do not understand the question you are asking.
It is certainly possible to pass a time vector to a different function that the numerical differential equation solvers can use. See for example Parameter Estimation for a System of Differential Equations where the time vector is passed to the objective function, ode45 integrates the system of differential equations using it, and returns a matrix that is then used to fit the data.
It is also possible to use a time vector that the numerical differential equation solvers create, in other functions and assignments.
.
  4 comentarios
Paulina Wienchol
Paulina Wienchol el 8 de Oct. de 2021
I have system of ODE written as a function (I call it subprogram):
function dydx = process(x,y,cond)
a = x/cond.vel; % <- here I want to use derivative of time. (actually of lenght, but doesn't matter)
.
.
dydx = zeros(2,1);
dydx(1) = -r*a*y(1);
dydx(2) = (Q_rad/1000 + H_ox- H_out-H_chem_out+Q_chem_char_in-Q_chem_char_out)/grate_char;
It is basically system of mass and energy balances descibing the combustion process. I want to solve mass of the fuel and its temperature depending on lenght of the grate (since it is steady state process).
My 'a' in the code above is the derrivative of time, 'x' is suppose to be derrivative of lenght (here is my problem) and cond.vel is velocity of the grate (defined).
I'm solving this system using ode45 solver in another script. Piece of this script:
options = odeset('Events',@(t,y)findEvents3(t,y,cond));
[x2,y2,te2,xe2,ie2] = ode45(@(x,y)process(x,y,cond),[te1 cond.l_bed],[xe1(1) xe1(2)],options);
The problem is that ode45 solver adjusts the time step by default, whereas I have to know this time step to one of equations in my function 'process'. Is that clear for you?
Sorry, I'm beginner in MatLab and maybe I am not very specific.
Star Strider
Star Strider el 8 de Oct. de 2021
The numerical differential integration funcitons use adaptive time steps, however they will output their results at specific times if ‘tspan’ is a vector of more than 2 elements, as the code I linked to demonstrates. The derivatives are as ‘process’ here creates them, and the time instants are supplied by ode45 here. There is no need to do anything with the time argument unless it is used in the calculation of the differential equations (and it does not appear to be here).
.

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by