solving a system of ODEs in 3x3 matrix form

1 view (last 30 days)
chen tianle
chen tianle 1日7 Sep 2021
Commented: Star Strider 1日7 Sep 2021
The following allowed me to solve wit 2x2 matrix , how about 3x3 matrix ? what the code. thanks

Answers (1)

Star Strider
Star Strider 1日7 Sep 2021
The easiest way would be to use the expm function.
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
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)]
x =
eqn = diff(x) == A*x + b
eqn =
Y = dsolve(eqn, x1(0)==x10, x2(0)==x20, x3(0)==x30)
Y =struct with fields:
x2: [1×1 sym] x1: [1×1 sym] x3: [1×1 sym]
Y.x1
ans =
Y.x2
ans =
Y.x3
ans =
sympref('AbbreviateOutput',false);
Y = vpa(simplify([Y.x1; Y.x2; Y.x3], 500), 3)
Y =
Setting the intital conditions to 0 :
Y = dsolve(eqn, x1(0)==0, x2(0)==0, x3(0)==0)
Y =struct with fields:
x2: [1×1 sym] x1: [1×1 sym] x3: [1×1 sym]
% sympref('AbbreviateOutput',false);
Y = vpa(simplify([Y.x1; Y.x2; Y.x3], 500), 3)
Y =
.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!