Changing the initial variables when passing into an ode45 solver
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hariharan MK
el 13 de En. de 2021
Comentada: Hariharan MK
el 14 de En. de 2021
Hello,
Based on this link, I learnt that the initial variables can be modified when passing into a solver. However, I have only been able to make use of "Y = mx + C" equations. Hence I have been only been able to increase or decrease the length linearly. How do I code such that the variable can modelled to be increasing linearly to plateu to become a constant and finally decrease back to its original initial value? (i.e shape of a trapezium )
So far i have created a function that holds the equation of the trapezium where the variable increases until a certain time step after which it remains constant before decreasing to its initial value.
function length_output = length_equation(t,x)
%parameters
L_0 = x(5); %initial length
HS = x(7); %rate of change of length
%increasing portion
if t<= 20
L = L_0 + HS*t;
elseif (t>20) && (t<40)
L = L + HS*t;
else
L = L - HS*t;
end
length_output = L;
The problem that I am currently facing is that the Previous L that was calculated is not stored hence, I keeping coming into errors that tells me that L is not defined at time step 21
Is there such a way that ode45 can accept changing variables that are not linear in nature?
Appreciate your help!
0 comentarios
Respuesta aceptada
Steven Lord
el 13 de En. de 2021
I would call the ODE solver three times.
First, solve over the time span [0, 20].
Next, use the final value from that first ODE solver call as the initial condition for the second call that solves over the time span [20, 40].
Third, do the same as the second call but for the time span [40, your_end_time].
If you don't know when the changes will occur but have some way to detect when they should occur, use an events function. See the ballode example for an illustration of this technique.
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!