![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279176/image.png)
Solving a mass-spring-damper system with ode45
์กฐํ ์: 122 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Kebels3
2020๋
3์ 24์ผ
๋๊ธ: Francescogiuseppe Morabito
2020๋
5์ 3์ผ
Hi guys
This code is for a with mass-spring-damper system
? = 50 kg
? = 100 N/m
? = 0.1 Ns/m
F = @(t, x) [x(2); -0.1/50*x(2) - 2*x(1)];
T = 0:0.001:10;
S = [0.5 0];
[t, y] = ode45(F, T, S);
plot(t,y)
legend({'Position', 'Speed'});
ylabel('Position / Speed [m / m/s]')
xlabel('Time [s]')
title(['mass-spring-damper system']);
But now the springforce is changed to ?? = 1250?3 โ 1125?2 + 350?
How do i change this in the code?
Can you guys help me out
Greets Jeroen
๋๊ธ ์: 3
์ฑํ๋ ๋ต๋ณ
Ameer Hamza
2020๋
3์ 24์ผ
If you are considering a mass-spring system vibrating under the influence of an external force Fv, then try the following code
T = 0:0.001:10;
S = [0.5 0];
[t, y] = ode45(@odefun, T, S);
plot(t,y)
legend({'Position', 'Speed'});
ylabel('Position / Speed [m / m/s]')
xlabel('Time [s]')
title('mass-spring-damper system');
function dydt = odefun(~,x)
F = 1*x(1)^3 - 1*x(1)^2 + 1*x(1);
dydt = [x(2);
- F - 0.1/50*x(2) - 2*x(1)];
end
Output
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279185/image.png)
๋๊ธ ์: 3
Ameer Hamza
2020๋
5์ 2์ผ
I cannot run the code because I don't have the values of the variables. And it is difficult to diagnose an issue without that. I recommend you to start a new question and include the code used to call ode45 along with the value of variables. You can then post the link in the next comment so that I will get a notification.
Francescogiuseppe Morabito
2020๋
5์ 3์ผ
thank you Ameer, this is the link: https://uk.mathworks.com/matlabcentral/answers/522631-solving-second-order-ode-problem-with-ode-45.
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Programming์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!