ODE45 with a vector input
8 次查看(过去 30 天)
显示 更早的评论
Hey, how can I solve an ode function with a changing input of my choosing: example:
I would like to solve the simple spring and defuse equation while inputting the external force at given time.
I would create a function for the differential equations:
if true
function dy = springdef(y,u)
k=1.5; %just values
m=3;
d=0.3;
% main differential equations
dy(1,1) = y(2);
dy(2,1) = -k/m*y(1)+u/m-d/m*y(2);
end
than I would calculate the result by using the ode45
if true
[t,y] = ode45(@(t,y)springdef(y,u),tspan,y0);
end
yet I don't find a way to choose u in advance (creating a vector for u for different values).
I can define a single input - u=0
or i can have a controller adjust the input - u= K*(y-[0,0]) but I don't find a way to preset the force u
such as u=[0,0,1,1,0,0] (of curse length(u) = length(tspan) )
0 个评论
采纳的回答
Torsten
2018-6-28
The example
"ODE with Time-Dependent Terms" under
https://de.mathworks.com/help/matlab/ref/ode45.html
should show you how to proceed.
Best wishes
Torsten.
2 个评论
Torsten
2018-6-29
The ODEs uniquely determine the solution - you can't constrain a variable to a max value. If you want to do this, you will have to adapt your u dependent on time.
Best wishes
Torsten.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!