MATLAB: Solve system of 2nd order differential equations with initial conditions

odeoscillations

I have system of two second-order ODE, and initail conditions
phi1 = 8 degree
phi2 = – 4 degree
phi1' = 0
phi2' = 0
And here is my func and conditions declaration
I'll try to solve this with ode45 but cant understand how i can use initial conditions and simplify this for solver

Best Answer

syms phi1(t) phi2(t)
g = 9.8;
m = 1;
k = 1;
c = 1;
l = 1;
l0 = 0.75;
dphi1=diff(phi1,t);
dphi2=diff(phi2,t);
eq1 = -(m * g * l * sind(phi1) + k * (l0^2) * cosd(phi1) * (sind(phi1) - sind(phi2)) + c * (l0^2) * cos(phi1) * (cos(phi1) * dphi1 - cosd(phi2) * dphi2))/(m * (l^2)) == diff(phi1, t ,2);
eq2 = -(m * g * l * sind(phi2) - k * (l0^2) * cosd(phi2) * (sind(phi1) - sind(phi2)) - c * (l0^2) * cos(phi2) * (cos(phi1) * dphi1 - cosd(phi2) * dphi2))/(m * (l^2)) == diff(phi2, t ,2);
vars = [phi1(t) ; phi2(t)]
V = odeToVectorField([eq1,eq2])
M = matlabFunction(V,'vars', {'t','Y'})
interval = [0 1.5]; %time interval
y0 = [8 0 -4 0]; %initial conditions
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),1000);
yValues = deval(ySol,tValues,1); %number 1 denotes first solution likewise you can mention 2 , 3 & 4 for the next three solutions
plot(tValues,yValues)