![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161358/image.png)
How to solve a non-linear system of differential equations?
조회 수: 4 (최근 30일)
이전 댓글 표시
Pacao Andrés Barros Díaz
2022년 10월 18일
댓글: Pacao Andrés Barros Díaz
2022년 10월 22일
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161253/image.png)
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
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]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161268/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161273/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161278/image.png)
and thus
A *
= b
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161283/image.png)
Where
= 4x1 vector [
;
;
;
]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161283/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161293/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161298/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161303/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161308/image.png)
b = 4x1 right hand side vector (nonlinear functions of
,
,
, Q, and constants)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161268/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161273/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161278/image.png)
A = 4x4 coefficients of
elements in your equations
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161283/image.png)
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
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161353/image.png)
추가 답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!