Need Help Solving a system of 2nd and 1st Order ODEs

1 visualización (últimos 30 días)
Sherif Magdy
Sherif Magdy el 25 de Dic. de 2020
Comentada: Sherif Magdy el 28 de Dic. de 2020
I have three differenital equations modeling a suspension system
Variables are Xu, Xs, X3 while Xo is an input that is generated by a white noise. Everything else is a constant
I have been trying to solve it for some time now but for some reason the solutions are always either zero or completely wrong.
Any help would be greatly appreciated as I have only just started using MATLAB.
Here is my code:
function dy = mysys(t,y,T,Xo)
format long
Xo = interp1(T,Xo,t);
k1 = 15000; k2 = 15000; kt = 200000; c1 = 1000; c2 = 1000; Ms=300; Mu=40;
dy(1) = y(4);
dy(2) = y(5);
dy(3) = y(6);
dy(4) = ((k1/Ms)*(y(2)-y(3)) + (c1/Ms)*(y(5)-y(4)));
dy(3) = (y(5) - (k2/c2)*(y(3)-y(1)) - (k2/c2)*(y(2)-y(3)))
dy(6) = ((kt/Mu)*(Xo-y(2)) - (c1/Mu)*(y(5)-y(4)) - (c2/Mu)*(y(5)-y(6)) - (k2/Mu)*(y(2)-y(3)));
dy = dy(:);
timerange = [0 10];
y0 = [0 0 0 0 0 0];
T = road_xo_time.Time;
Xo = road_xo_time.Data;
[t,y] = ode45(@(t,y) mysys(t,y,T,Xo), timerange, init_cond);
plot(t, y(:,1))

Respuesta aceptada

Alan Stevens
Alan Stevens el 27 de Dic. de 2020
I think you should be passing only 5, not 6, parameters to your mysys function, which is better written as
function dy = mysys(t,y,T,Xo)
Xo = interp1(T,Xo,t);
k1 = 15000; k2 = 15000; kt = 200000; c1 = 1000; c2 = 1000; Ms=300; Mu=40;
xs = y(1);
xu = y(2);
x3 = y(3);
vs = y(4);
vu = y(5);
v3 = vu - (k1/c2)*(x3 - xs) - (k2/c2)*(xu - x3);
dy = [vs; % dxs/dt
vu; % dxu/dt
v3; % dx3/dt
(k1/Ms)*(xu - x3) + (c1/Ms)*(vu - vs); % d2xs/dt2
(kt/Mu)*(X0 - xu) - (c1/Mu)*(vu - vs) - (c2/Mu)*(vu - v3) - (k2/Mu)*(xu - x3)]; % d2xu/dt2
end
You can, of course, use y's where I used x's.
  1 comentario
Sherif Magdy
Sherif Magdy el 28 de Dic. de 2020
Thanks so much!
I have been stuck for some time and now it finally works.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Statics and Dynamics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by