solving a system of ODEs in 3x3 matrix form
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The following allowed me to solve wit 2x2 matrix , how about 3x3 matrix ? what the code. thanks
0 Kommentare
Antworten (1)
Star Strider
am 17 Sep. 2021
The expression changes slightly:
A = rand(3);
b = rand(3,1);
t = 0:0.1:10;
for k = 1:numel(t)
y(:,k) = expm(A*t(k))*b;
end
figure
plot(t, y)
grid
Experiment with your own ‘A’ and ‘b’ arrays.
.
3 Kommentare
Star Strider
am 17 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;
for k = 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:
syms t 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)
.
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!