Solve numerically a system of first-order differential equations

23 vues (au cours des 30 derniers jours)
Roderick
Roderick le 31 Mar 2020
Commenté : Star Strider le 31 Mar 2020
Hello everyone,
I have the following set of coupled first-order differential equations:
a*x'/z+y'=b;
x'/z-a*y'=c*sin(2*y);
z'=d*(e/z-(f+g*sin(2*y))*z);
where a, b, c, d, e, f, and g are some known parameters.
I was wondering which could be a good attempt to solve numerically this system of differential equations.
Any suggestion?

Réponse acceptée

Star Strider
Star Strider le 31 Mar 2020
Create the function symbolically:
syms a b c d e f g t x(t) y(t) z(t) T Y
Dx = diff(x);
Dy = diff(y);
Dz = diff(z);
Eqn1 = a*Dx/z+Dy == b;
Eqn2 = Dx/z-a*Dy == c*sin(2*y);
Eqn3 = Dz == d*(e/z-(f+g*sin(2*y))*z);
Eqn1s = simplify(lhs(Eqn1) - rhs(Eqn1), 'Steps', 100);
Eqn2s = simplify(lhs(Eqn2) - rhs(Eqn2), 'Steps', 100);
Eqn3s = simplify(lhs(Eqn3) - rhs(Eqn3), 'Steps', 100);
[VF,Subs] = odeToVectorField(Eqn1s, Eqn2s, Eqn3s);
odefcn = matlabFunction(VF, 'Vars',{T Y a b c d e f g});
producing (lightly edited):
odefcn = @(T,Y,a,b,c,d,e,f,g)[(Y(3).*(a.*b+c.*sin(Y(2).*2.0)))./(a.^2+1.0);(b-a.*c.*sin(Y(2).*2.0))./(a.^2+1.0);-(d.*(-e+f.*Y(3).^2+g.*sin(Y(2).*2.0).*Y(3).^2))./Y(3)];
Then use the solver of your choice to integrate it.
  8 commentaires
Roderick
Roderick le 31 Mar 2020
No problem at all. Thank you again!
Star Strider
Star Strider le 31 Mar 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by