solve matrix differential equations with ode45
Afficher commentaires plus anciens
Hi
I want to solve dy/dt=Ay(t) in matlab numerically but having a hard time coming up with a working code. My numerican and analytical results should match. Any help appreciated.
% analytical
A = [0 1;8 -2]
syms t;
[M,J] = jordan(A);
y = M * expm(J*t) * inv(M)
% numerical
5 commentaires
Torsten
le 27 Nov 2022
And what does a matrix as result mean ?
mpz
le 28 Nov 2022
mpz
le 28 Nov 2022
Torsten
le 28 Nov 2022
But you have to clarify in advance that y is supposed to be a matrix (2x2) matrix of functions, not a 2x1 vector of functions which is the usual interpretation when an ODE is written as
dy/dt = A*y(t)
Réponses (1)
syms t y1(t) y2(t)
A = [0 1;8 -2];
Y = dsolve(diff([y1;y2],t)==A*[y1;y2])
y1 = Y.y1;
y2 = Y.y2;
diff(y1,t)-y2
diff(y2,t)-8*y1+2*y2
To compare with a numerical solution, you need to prescribe initial conditions for y1 and y2.
Here is your corrected solution:
syms t
A = [0 1;8 -2];
[V,J] = jordan(A)
y = V*exp(diag(J)*t)
2 commentaires
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





