MATLAB Answers

How to solve differential equations involving matrices?

2 views (last 30 days)
Conner Eddy
Conner Eddy on 27 Apr 2021
Answered: Bjorn Gustavsson on 28 Apr 2021
I am trying to solve the differential equation below.
E11 through E44 are all functions of some combination of P11 through P44.
How can I solve this in MATLAB?

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 28 Apr 2021
Based off of your description I see no difference betwee solving these 4 x 4 coupled ODEs and solving them as 16 x 1 coupled ODEs. Using that you can simply rearrange your components in a format matlab's ODE-integrating functions expect. Something like this:
function dPdt = ode4by4as16by1(t,P,Perhaps_pars)
p1 = Perhaps_pars(1); % If you need some parameters
p2 = Perhaps_pars(2); % that you might want to tune between different runs...
E11 = E11fcn(t,P,p1); % possibly you prefer E11fcn(t,reshape(P,[4,4],p1)
E21 = E21fcn(t,P,p2);
% etc
dPdt = [E11;
E21;
E31;
% etc
E44];
end
This should be possible to integrate with ode45:
P0 = randn(4,4);
t_span = [0,exp(pi)];
[t,P] = ode45(@(t,P,[log(2),2^.5]),t_span,P0(:));
HTH

Community Treasure Hunt

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

Start Hunting!

Translated by