# Chapter - 11 : Special Matrices and Gauss-Seidel¶

## Ex:11.1 Pg: 297¶

In :
from numpy import mat
A = mat([[2.04,-1,0,0],[-1,2.04,-1,0],[0,-1,2.04,-1],[0,0,-1,2.04]])
B = mat([[40.8],[0.8],[0.8],[200.8]])
g = A[0,1]
f1 =A[0,0]
e2 = A[1,0]
f2 = A[0,0] - e2 * A[1,0]
e3 = A[1,0]/f2
f3 = A[0,0] - e3 * A[1,0]
e4 = A[1,0]/f3#
f4 = A[0,0] - e4 * A[1,0]
M = mat([[f1,g,0,0],[e2,f2,g,0],[0,e3,f3,g],[0,0,e4,f4]])
L = mat([[1,0,0,0],[M[1,0],1,0,0],[0,M[2,1],1,0],[0,0,M[3,2],1]])
U = mat([[M[0,0],g,0,0],[0,M[1,1],g,0],[0,0,M[2,2],g],[0,0,0,M[3,3]]])
r1 = B[0,0]
r2 = B[1,0] - e2*B[0,0]
r3 = B[2,0] - e3*r2#
r4= B[3,0] - e4*r3#
N = mat([[r1],[r2],[r3],[r4]])
T4 = r4/U[3,3]
T3 = (r3 - g*T4)/U[2,2]
T2 = (r2 - g*T3)/U[1,1]
T1 = (r1 - g*T2)/U[0,0]
print "T1 = ",T1
print "T2 = ",T2
print "T3 = ",T3
print "T4 = ",T4

T1 =  151.165722019
T2 =  267.578072919
T3 =  236.681195836
T4 =  214.451566586


## Ex:11.2 Pg: 299¶

In :
from numpy import mat,sqrt
A = mat([[6,15,55],[15,55,225],[55,225,979]])
sl = 0
l11 = sqrt(A[0,0])
#for second row
l21 = (A[1,0])/l11
l22 = (A[1,1] - l21**2)**(0.5)
#for third row
l31 = (A[2,0])/l11#
l32 = (A[2,1] - l21*l31)/l22#
l33 = (A[2,2] - l31**2 - l32**2)**(0.5)#
L = mat([[l11,0,0],[l21,l22,0],[l31,l32,l33]])
print "\nL = \n",L

L =
[[  2.44948974   0.           0.        ]
[  6.12372436   4.18330013   0.        ]
[ 22.45365598  20.91650066   6.11010093]]


## Ex:11.3 Pg: 301¶

In :
#3x - 0.1y - 0.2z = 7.85
#0.1x + 7y - 0.3z = -19.3
#0.3x - 0.2y + 10z = 71.4
Y = 0#
Z = 0#
x=range(1,3)
y=range(1,3)
z=range(1,3)
for i in range(1,3):
x[i-1]= (7.85 +0.1*Y+0.2*Z)/3#
X = x[i-1]
y[i-1]= (-19.3 - 0.1*X +0.3*Z)/7#
Y = y[i-1]#
z[i-1]= (71.4 - 0.3*X+0.2*Y)/10#
Z = z[i-1]
if i==2:
ex = (x[i-1] - x[(i-2)])*100/x[i-1]
ey = (y[i-1] - y[i-2])*100/y[i-1]
ez = (z[i-1] - z[i-2])*100/z[i-1]

print "x through two iterations =",x[0:1]
print "y through two iterations =",y[0:1]
print "z through two iterations =",z[0:1]
print "error of x = ",ex,"%"
print "error of y = ",ey,"%"
print "error of z = ",ez,"%"

x through two iterations = [2.6166666666666667]
y through two iterations = [-2.7945238095238096]
z through two iterations = [7.005609523809525]
error of x =  12.50234999 %
error of y =  -11.7977361365 %
error of z =  -0.075978454143 %


## Ex:11.4 Pg: 307¶

In :
from __future__ import division

from numpy import mat
A = mat([[1,0.5,1/3],[1,2/3,1/2],[1,3/4,3/5]])
B = mat([[1.833333],[2.166667],[2.35]])
U = A**-1
X = U*B#
x = X[0,0]
y = X[1,0]
z = X[2,0]
print "x = ",x
print "y = ",y
print "z = ",z

x =  0.999991
y =  1.000044
z =  0.99996


## Ex:11.5 Pg: 309¶

In :
from __future__ import division
from numpy import mat
A = mat([[1,0.5,1/3],[1,2/3,1/2],[1,3/4,3/5]])
B = mat([[1.833333],[2.166667],[2.35]])
U = A**-1
X = U*B#
x = X[0,0]
y = X[1,0]
z = X[2,0]
print "x = ",x
print "y = ",y
print "z = ",z

x =  0.999991
y =  1.000044
z =  0.99996


## Ex:11.6 Pg: 310¶

In :
from numpy import mat
A = mat([[1,0.5,1/3],[1/2,1/3,1/4],[1/3,1/4,1/5]])
B = mat([[1.833333],[1.083333],[0.783333]])
U = A**-1
X = U*B#
x = X[0,0]
y = X[1,0]
z = X[2,0]
print "x = ",x
print "y = ",y
print "z = ",z

x =  0.999999
y =  1.000008
z =  0.99999
{"ft_lang_label":"__label__en","ft_lang_prob":0.51361656,"math_prob":1.0000093,"size":2365,"snap":"2020-24-2020-29","text_gpt3_token_len":1354,"char_repetition_ratio":0.15417196,"word_repetition_ratio":0.27105263,"special_character_ratio":0.7124736,"punctuation_ratio":0.26152074,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99951375,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-05-27T06:36:00Z\",\"WARC-Record-ID\":\"<urn:uuid:938e8531-9048-4357-a5bc-65eb3cba256d>\",\"Content-Length\":\"230546\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d0b109f3-ae49-466a-be23-f1c8efd9d545>\",\"WARC-Concurrent-To\":\"<urn:uuid:836677ab-2151-45aa-a1a1-2577aad8a11f>\",\"WARC-IP-Address\":\"213.239.210.233\",\"WARC-Target-URI\":\"https://tbc-python.fossee.in/convert-notebook/Numerical_Methods_For_Engineers_by_S._C._Chapra_And_R._P._Canale/Chapter11_2.ipynb\",\"WARC-Payload-Digest\":\"sha1:GZX6NSGPGZAHJCT6VSGV5X55RESLPYLO\",\"WARC-Block-Digest\":\"sha1:QBPTTGDIZJCZSKWB45BZEGXNEG3IAM3U\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347392141.7_warc_CC-MAIN-20200527044512-20200527074512-00469.warc.gz\"}"}