Solving coupled 2nd order differential equations
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Joe Hasrouny
le 14 Mai 2020
Commenté : Star Strider
le 20 Juil 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 commentaires
Réponse acceptée
Star Strider
le 14 Mai 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 commentaires
Haseeb Hashim
le 20 Juil 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
le 20 Juil 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!