Solving coupled 2nd order differential equations

12 ビュー (過去 30 日間)
Joe Hasrouny
Joe Hasrouny 2020 年 5 月 14 日
コメント済み: Star Strider 2022 年 7 月 20 日
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;

採用された回答

Star Strider
Star Strider 2020 年 5 月 14 日
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 件のコメント
Haseeb Hashim
Haseeb Hashim 2022 年 7 月 20 日
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
Star Strider 2022 年 7 月 20 日
@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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by