solving a system of ODEs in 3x3 matrix form
1 view (last 30 days)
Show older comments
The following allowed me to solve wit 2x2 matrix , how about 3x3 matrix ? what the code. thanks
0 Comments
Answers (1)
Star Strider
1日7 Sep 2021
The expression changes slightly:
A = rand(3);
b = rand(3,1);
t = 0:0.1:10;
fork = 1:numel(t)
y(:,k) = expm(A*t(k))*b;
end
figure
plot(t, y)
grid
Experiment with your own
‘A’
and
‘b’
数组。
.
3 Comments
Star Strider
1日7 Sep 2021
The code works. The problem is that
‘b’
is
0
so the output is
0
, and there was an error in
‘A’
(spaces are delimiters, so the dimensions did not originally match) —
A = [ 3 1 1 ; 0 3 -1 ; 0 -1 3] ;
b = ones(3,1)*eps;% 'b': Small, Non-Zero Value
t = 0:0.1:1;
fork = 1:numel(t)
y(:,k) = expm(A*t(k))*b;
end
figure
plot(t, y)
grid
This would also be the situation doing symbolic integration:
symst x1(t) x2(t) x3(t) x10 x20 x30
x = [x1(t); x2(t); x3(t)]
eqn = diff(x) == A*x + b
Y = dsolve(eqn, x1(0)==x10, x2(0)==x20, x3(0)==x30)
Y.x1
Y.x2
Y.x3
sympref('AbbreviateOutput',false);
Y = vpa(simplify([Y.x1; Y.x2; Y.x3], 500), 3)
Setting the intital conditions to
0
:
Y = dsolve(eqn, x1(0)==0, x2(0)==0, x3(0)==0)
% sympref('AbbreviateOutput',false);
Y = vpa(simplify([Y.x1; Y.x2; Y.x3], 500), 3)
.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!