solve matrix differential equations with ode45
21 views (last 30 days)
Show older comments
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 Comments
Torsten
on 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)
Answers (1)
Torsten
on 27 Nov 2022
Edited: Torsten
on 28 Nov 2022
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!