Solving coupled 2nd order differential equations
19 views (last 30 days)
Show older comments
Joe Hasrouny
on 14 May 2020
Commented: Star Strider
on 20 Jul 2022
Hello,
I am trying to solve the following 2nd order coupled diffrential equations:

So i started with the following code - I don't know if it's right at first place and i don't know how to continue (using ode45).
I want to plot three things : plot(x,y) , plot(t,y) , plot(t,x).
Any help will be appreciated .
syms O a g L x(t) y(t) t Y ;
dx = diff(x);
d2x = diff(x,2);
dy = diff(y);
d2y = diff(y,2);
Eq1 = d2x == 2*O*sin(a)*dy - (g/L)*x(t);
Eq2 = d2y == -2*O*sin(a)*dx - (g/L)*y(t);
[VF,Subs] = odeToVectorField(Eq1, Eq2)
ftotal = matlabFunction(VF,'Vars',{O,a,g,L,Y});
O=rand;
a=rand;
g=9.81;
L=rand;
0 Comments
Accepted Answer
Star Strider
on 14 May 2020
Try this:
syms O a g L x(t) y(t) t Y ;
dx = diff(x);
d2x = diff(x,2);
dy = diff(y);
d2y = diff(y,2);
Eq1 = d2x == 2*O*sin(a)*dy - (g/L)*x(t);
Eq2 = d2y == -2*O*sin(a)*dx - (g/L)*y(t);
[VF,Subs] = odeToVectorField(Eq1, Eq2)
ftotal = matlabFunction(VF,'Vars',{t,Y,O,a,g,L});
O=rand;
a=rand;
g=9.81;
L=rand;
tspan = [0 25]; % Choose Appropriate Simulation Time
ic = [0 1 0 1]; % Choose Appropriate Initial Conditions
[t,y] = ode45(@(t,y) ftotal(t,y,O,a,g,L), tspan, ic);
figure
plot(t, y)
grid
legend(string(Subs))
The initial conditions and parameters need to be appropriate for the simulation you want to do. The simulation time can be anything appropriate.
4 Comments
Haseeb Hashim
on 20 Jul 2022
Hi I wanted to ask 1 thing the solution vector y contains solution in what order i-e the x displacement first or y displacement first along with the velocities please respond quick if you can
Star Strider
on 20 Jul 2022
@Haseeb Hashim — The first column of the integrated result coresponds to the first differential equation in the original system, the second column to the second differential equation, and so for any others.
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!