How to solve a non-linear system of differential equations?

조회 수: 16 (최근 30일)
Hello I´m trying to solve this system of differential equations, but I don´t know how. I´ve tried with dsolve, but Matlab dont find an analytical solution, So I try with ODEs functions, but I dont know how to convert my symbolic system to a system that Ode45 can solve. I try with matlabfunction but I dont know use it fine.
clc; clearvars;
syms wp(t) wt(t) ws(t) Q(t);
p = 840;
A = 0.0097;
ap = deg2rad(18.01);
at = deg2rad(-59.04);
as = deg2rad(59.54);
Rp = 0.11;
Rs = 0.060;
Rt = 0.066;
Ts = 0;
Tp = 200;
Tt = -Tp;
Ip = 0.092;
It = 0.026;
Is = 0.012;
Sp = -0.001;
St = -0.00002;
Ss = 0.002;
Lf = 0.28;
PL = 0.5;
eqn1 = Ip*diff(wp,t) == - p*Q(t)*(wp(t)*Rp^2 + Rp*Q(t)/A*tan(ap) - ws(t)*Rs^2 - Rs*Q(t)/A*tan(as)) + Tp;
eqn2 = It*diff(wt,t) == - p*Q(t)*(wt(t)*Rt^2 + Rt*Q(t)/A*tan(at) - wp(t)*Rp^2 - Rp*Q(t)/A*tan(ap)) + Tt;
eqn3 = Is*diff(wt,t) == - p*Q(t)*(ws(t)*Rs^2 + Rs*Q(t)/A*tan(as) - wt(t)*Rt^2 - Rt*Q(t)/A*tan(at)) + Ts;
eqn4 = p*(Sp*diff(wp,t) + St*diff(wt,t) + Ss*diff(ws,t)) + p*Lf/A*diff(Q,t) == p*(Rp^2*wp(t)^2 + Rt^2*wt(t)^2 + Rs^2*ws(t)^2 - Rs^2*wp(t)*ws(t) - Rp^2*wt(t)*wp(t) - Rt^2*ws(t)*wt(t)) + wp(t)*Q(t)/A*p*(Rp*tan(ap) - Rs*tan(as)) + wt(t)*Q(t)/A*p*(Rt*tan(at) - Rp*tan(ap)) + ws(t)*Q(t)/A*p*(Rs*tan(as) - Rt*tan(at)) - PL*p;
eqns = [eqn1,eqn2,eqn3,eqn4];
vars = [wt(t) ws(t) wp(t) Q(t)];
S = dsolve(eqn1,eqn2,eqn3,eqn4, wp(0)==0, wt(0)==330,ws(0)==300,Q(0)==0.05);
odesfcn = matlabFunction(eqns,'Vars',{t,wt,ws,wp,Q});
t_interval = [0,10];
init_cond = [0,0,0,0]';
[t,y] = ode45(odesfcn, t_interval , init_cond);
plot(t,y(:,1),'b',t,y(:,2),'r',t,y(:,3),'g','LineWidth',2);
S = ['wp(t)';'wt(t)';'ws(t)'];
legend(S,'Location','Best')
grid on
  댓글 수: 1
James Tursa
James Tursa 2022년 10월 19일
It looks like you are missing terms in your eqn1, eqn2, and eqn3.

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2022년 10월 19일
편집: James Tursa 2022년 10월 19일
Your equations are linear in the derivatives, so you can form your equations as a matrix equation, then write a derivative function that uses backslash at each step to find the individual derivatives. E.g., let
y = [ ; , , Q]
and thus
A * = b
Where = 4x1 vector [ ; ; ; ]
b = 4x1 right hand side vector (nonlinear functions of , , , Q, and constants)
A = 4x4 coefficients of elements in your equations
function ydot = myderivative(t,y, ... other constants ...)
A = (form the 4x4 matrix elements here)
b = (form the right hand side 4x1 vector elements here)
ydot = A\b;
end
Then use this function in your call to the integrator (e.g., ode45):
ode45(@(t,y)myderivative(t,y, ... other constants ...),tspan,initial_conditions)
  댓글 수: 3
James Tursa
James Tursa 2022년 10월 19일
편집: James Tursa 2022년 10월 19일
Well, the equations/coefficients have to be typed in manually in either case. If they are already typed in one form then yes equationsToMatrix( ) could help. But in fact it looks like there already are mistakes in eqn1, eqn2, and eqn3 above because I don't see any term.
Pacao Andrés Barros Díaz
Pacao Andrés Barros Díaz 2022년 10월 22일
Thank you, It's works. I fixed eqns 1,2 and 3 and use equationsToMatrix to create A and B.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2022년 10월 19일
Hi Pacao,
The missing step is a call to odeToVectorField before the call to matlabFunction. Check that first doc page and then feel free to post back if it's still not working for you.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by