1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
disp('the lower triangular matrix is:')
L=[1 0 0;-1 1 0;2 -5 1];
disp(L)
disp('the upper triangular matrix is:')
U=[3 -7 -2;0 -2 -1;0 0 -1];
disp(U)
disp('the RHS of the equations are')
b=[-7;5;2];
disp(b)
disp('combining matrices L and b')
c=[L b];
disp(c)
disp('performing row operations')
disp('R2=R2+R1')
c(2,:)=c(2,:)+c(1,:)
disp(c)
disp('R3=R3-2*R1')
c(3,:)=c(3,:)-2*c(1,:)
disp(c)
disp('R3=R3+5*R2')
c(3,:)=c(3,:)+5*c(2,:)
disp(c)
y=c(:,4)
disp(y,'y=')
disp('combining U and y')
d=[U y];
disp(d)
disp('performing row operations')
disp('R3=R3/-6')
d(3,:)=d(3,:)/(-1)
disp(d)
disp('R2=R2+R3 and R1=R1+2*R3')
d(2,:)=d(2,:)+d(3,:)
d(1,:)=d(1,:)+2*d(3,:)
disp(d)
disp('R1=R1-3.5*R2')
d(1,:)=d(1,:)-3.5*d(2,:)
disp(d)
disp('R1=R1/3 and R2=R2/-2')
d(1,:)=d(1,:)/3
d(2,:)=d(2,:)/(-2)
disp(d)
disp('the solution is:')
x=d(:,4)
disp(x,'x=')
|