How to solve system of second order differential equations
31 次查看(过去 30 天)
显示 更早的评论
Hi there everyone.
I am trying to solve a system of second order differential equations for a mass spring damper as shown in the attached picture using ODE45. The data etc is below;
top mass (ms) = 100
lower mass (mu) = 18
spring rate sprung (Ks) = 20,000
spring rate unsprung (Ku) = 167,000
Damping ratio sprung (Cs) = 1200
Damping ratio unsprung (Cu) = 6
sprung displacement (xs) = unknown, variable trying to calculate
unsprung displacement (xu) = unknown, variable trying to calculate
road vertical displacement (y) = 1-cos^2(theta) bump, 260mm long, 50mm high at peak
I have been struggling to get any data other than a straight line when it should show something like in the graph in the second picture. I know that i'll have to modify the output to give me the positions of the sprung and unsprung masses (m1 & m2). However i don't understand why i'm getting these results. The only output i have managed to get is attached and looks like a typical damping graph for a motorcycle which is what i am modelling. However i'm looking to get positions.
I know i have to turn the equations into a first order system (for some weird reason when mathematica can do it as is?!) so following some of the posts on here i have done that, but what's confusing me most is that i have to define xu and xs, which is what i am trying to find? Basically i'm just trying to bodge it and could use some guidance and an explanation past the documentation as it from what i've found it is just talking about a system of equations to be solved, or solving a single second order differential, not a system of them.
I have put my code below which gives the damping type output, however i don't want to have to define xs and xu as that's what i'm trying to determine. the data in the mat file is also included as an attachment So any help would be greatly appreciated. Thanks, Ross
function dydt = MSS(t,y)
load('Standard_European_Bump_Data.mat','length','height')
height1 = height/1000
length1 = length/1000
h_vs_l = plot(length1, height1)
ms = 100
mu = 18
Ks = 20000
Ku = 167000
Cs = 1200
Cu = 6
y = height1
xu = zeros(360,1)
xs = zeros(360,1)
% y2' = (Ks/ms)*y1 + (Cs/ms)*y2 == 0
% y4' = (-Ks/ms)*y1 + (-Cs/ms)*y + (Ku/mu)*y3 + (Cu/mu)*y4 == 0
y1 = (xs - xu)
y2 = resample((diff(y1)),361,360)
y3 = (xu - y)
y4 = resample((diff(y3)),361,360)
dy1 = y2
dy2 = y4
dy3 = (Ks/ms)*y1 + (Cs/ms)*y2
dy4 = (-Ks/ms)*y1 + (-Cs/ms)*y2 + (Ku/mu)*y3 + (Cu/mu)*y4
dydt = [dy1;dy2;dy3;dy4]
end
and the solving part of the code in a separate file
y0 = zeros(1440,1)
tspan = [0 10]
[t,y]=ode45(@Quarter_Car, tspan, y0)
y1 = (1:1:77)
% plot(t,y(:,1))
% hold on
% xlabel('time (s)')
% ylabel('Displacement??')
% axis([0,100,-120,120])
plot(t,y1)
4 个评论
Jan
2018-2-8
@Ross: If you hit the "{} Code" button and no code was selected before, the forum's interface inserts "if true; end" for unknown reasons - a kind of default code. Either delete it or simply select the code before hitting the button.
回答(1 个)
Jan
2018-2-8
编辑:Jan
2018-2-8
Your function calculates:
xu = zeros(360,1)
xs = zeros(360,1)
y1 = (xs - xu)
y2 = resample((diff(y1)),361,360)
y3 = (xu - y)
y4 = resample((diff(y3)),361,360)
If xu and xs contains zeros only, y1 and y2 must be zero also. The diff command is very strange here and it is meaningless to resample the data afterwards. I assume you try to create a system of 1st order is completely wrong. Please take a look into the example of the documentation, e.g. https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b.
This does not look meaningful also:
% y2' = (Ks/ms)*y1 + (Cs/ms)*y2 == 0
% y4' = (-Ks/ms)*y1 + (-Cs/ms)*y + (Ku/mu)*y3 + (Cu/mu)*y4 == 0
If y2' and y4' equals 0, you can omit the computations.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!