Changing the initial variables when passing into an ode45 solver
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!