Solving an ODE in matlab

์กฐํšŒ ์ˆ˜: 6 (์ตœ๊ทผ 30์ผ)
Kebels3
Kebels3 2020๋…„ 3์›” 11์ผ
๋Œ“๊ธ€: Bjorn Gustavsson 2020๋…„ 3์›” 11์ผ
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.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Ameer Hamza
Ameer Hamza 2020๋…„ 3์›” 11์ผ
ํŽธ์ง‘: Ameer Hamza 2020๋…„ 3์›” 11์ผ
You can use ode45 to solve such ODEs. See this example: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b to see how your differential equation is converted into two first order ODEs.
fun = @(t, x) [x(2); -0.1/50*x(2) - 2*x(1)];
time = 0:0.001:10;
initial_condition = [0.5 0];
[t, y] = ode45(fun, time, initial_condition);
plot(t,y)
legend({'position', 'velocity'});
  ๋Œ“๊ธ€ ์ˆ˜: 5
Ameer Hamza
Ameer Hamza 2020๋…„ 3์›” 11์ผ
Bjorn, good that you mentioned it, I didn't know this. Can you point to an example of such a scenario?
Bjorn Gustavsson
Bjorn Gustavsson 2020๋…„ 3์›” 11์ผ
The simplest example (straigh off the cuff) is gyration of electrically charged particles in a static homogeouns magnetic field - i.e. particle accelerated by a force:
Only one of the odeNM functions were close to conserving the particle energy and and gyro-radius, the other ones had either rather bad growth or loss of kinetic energy.
This is rather understandable, the odeNM cannot know excplicityl what constants of motion there should be - we might implement the equations of motion as coupled first-order ODEs in rather arbitrary order of the components of position and velocity.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (1๊ฐœ)

Bjorn Gustavsson
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:
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

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Programming์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ

Community Treasure Hunt

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

Start Hunting!

Translated by