summaryrefslogtreecommitdiff
path: root/1332/CH8/EX8.6/8_6.sce
blob: 2fb06a7ee114834af2c501b85a8b60787668bc02 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
//Example 8.6
//Block Jacobi Method
//Page no. 281
clc;clear;close;

A=[10,1,0,0,0,-1;1,10,1,0,0,0;2,0,20,1,0,0;0,0,1,10,-1,0;0,3,0,0,30,3;0,0,0,2,-2,20];        //equation matrix
B=[5;10;10;0;0;5]                     //solution matrix
disp(B,'B=',A,'A=')
for i=1:3
    for j=1:3
        A11(i,j)=A(i,j);
    end
    B1(i,1)=B(i,1);
end
for i=1:3
    for j=1:3
        A12(i,j)=A(i,j+3);
    end
end
for i=1:3
    for j=1:3
        A21(i,j)=A(i+3,j);
    end
end
for i=1:3
    for j=1:3
        A22(i,j)=A(i+3,j+3);
    end
    B2(i,1)=B(i+3,1);
end
disp(B2,'B2=',B1,'B1=',A22,'A22=',A21,'A21=',A12,'A12=',A11,'A11=');
A11_1=inv(A11);A22_1=inv(A22);
disp(A22_1,'Inverse of A22=',A11_1,'Inverse of A11=')
for i=1:3
    X1(i,1)=0;
    X2(i,1)=0;
end
for r=1:2
    X11=A11_1*(-1*A12*X2+B1);
    X22=A22_1*(-1*A21*X1+B2);
    X1=X11;
    X2=X22;
    disp(X1,'X1=')
    disp(X2,'X2=')
end
for i=1:6
    if(i<4)
        X(i,1)=X1(i,1);
    else
        X(i,1)=X2(i-3,1);
    end
end    
disp(X,'X=')
printf('\n\n\nNote : There is a computation error in calculation of X1(2)')