Solving coupled 2nd order differential equations
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joe Hasrouny
el 14 de Mayo de 2020
Comentada: Star Strider
el 20 de Jul. de 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 comentarios
Respuesta aceptada
Star Strider
el 14 de Mayo de 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 comentarios
Haseeb Hashim
el 20 de Jul. de 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
el 20 de Jul. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!