Vous êtes sur la page 1sur 2

4/13/15 8:52 AM

MATLAB Command Window

>> % thomas.m
% Solve the system Av=d for d using the Thomas Alogrithm
% ETHANE CALCULATION:
A=[1.111,-1,0,0,0
-0.111,1.111,-1,0,0
0,-0.111,1.111,-1,0
0,0,-0.111,1.111,-1
0,0,0,-0.111,1.111]
d=[0
27.5
300
0
0]
n = length(d);
u = zeros(n,1);
v = u;
w = A(1,1);
v(1) = d(1)/w;
% Forward sweep
for i=2:n
u(i-1) = A(i-1,i)/w;
w = A(i,i) - A(i,i-1)*u(i-1);
v(i) = ( d(i) - A(i,i-1)*v(i-1) )/w;
end
% Back substitution
for j=n-1:-1:1
v(j) = v(j) - (u(j)*v(j+1))
end
% end thomas.m
A =
1.1110
-0.1110
0
0
0

d =
0
27.5000
300.0000
0
0

-1.0000
1.1110
-0.1110
0
0

0
-1.0000
1.1110
-0.1110
0

0
0
-1.0000
1.1110
-0.1110

0
0
0
-1.0000
1.1110

1 of 2

4/13/15 8:52 AM
v =
0
27.1984
302.6505
37.3176
3.7284

v =
0
27.1984
339.9227
37.3176
3.7284

v =
0
363.3927
339.9227
37.3176
3.7284

v =
327.0861
363.3927
339.9227
37.3176
3.7284
>>

MATLAB Command Window

2 of 2

Vous aimerez peut-être aussi