How to solve a non-linear system of differential equations?
7 views (last 30 days)
Show older comments
Pacao Andrés Barros Díaz
on 18 Oct 2022
Commented: Pacao Andrés Barros Díaz
on 22 Oct 2022
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 Comment
Accepted Answer
James Tursa
on 19 Oct 2022
Edited: James Tursa
on 19 Oct 2022
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 Comments
James Tursa
on 19 Oct 2022
Edited: James Tursa
on 19 Oct 2022
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.
More Answers (1)
Paul
on 19 Oct 2022
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 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!