Solving an ODE in matlab
์ด์ ๋๊ธ ํ์
Can you guys help me?
?ฬ(?) = -(0.1/50) ?ฬ(?)-2?(?)
How to numerically integrate to find a solution for ??
Speed of the mass in time-step ? + ฮ? is:
?ฬ(? + ฮ?) โ ?ฬ(?) + ?ฬ(?) โ ฮ?
and the position in time-step ? + ฮ? is:
?(? + ฮ?) โ ?(?) + ?ฬ(?) โ ฮ?
I want to put the previous two equations in a loop and loop from ? = 0 s to ? = 10 s(step ฮ? = 0.001 s). And then plot those two graphs into in graph.
Assuming the mass is let go from initial displacement ?(0) = 0.5 m.
But I canโt get it to work in matlab.
์ฑํ๋ ๋ต๋ณ
์ถ๊ฐ ๋ต๋ณ (1๊ฐ)
Bjorn Gustavsson
2020๋
3์ 11์ผ
First thing you should learn/revise/refresh is how to convert higher-order ODEs to sets of coupled first-order ODEs.
You have an equation of motion (well it might be something completely different, but...)

By noting that
and
, you can convert your second-order ODE to two coupled first-oder ODEs:
and
, you can convert your second-order ODE to two coupled first-oder ODEs:

Now you have your equation in a format suitable for numerical integration with the odeNN-suite (starting with ode45 I think is the knee-jerk recommendation). To do that you write a function returning a vector with the left-hand-side of the two equations above as a function of time t and v and x. Something like this:
function dxdtdvdt = my_eq_o_motion(t,xv)
x = xv(1);
v = xv(2);
acceleration = % whatever you need for the acceleration as a function of x v and t
dxdtdvdt = [v;acceleration];
end
HTH
์นดํ ๊ณ ๋ฆฌ
๋์๋ง ์ผํฐ ๋ฐ File Exchange์์ Ordinary Differential Equations์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
์ ํ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!