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 CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by