# Chapter 7 Computations with Matrices¶

## Ex:7.4.1 Pg: 238¶

In [1]:
from __future__ import division
from numpy import mat,transpose,zeros
A=mat([[2 ,-1],[-1, 2]])
S=mat([[2, 0],[0, 2]])
T=mat([[0, 1],[1, 0]])
p=S**-1*T
b=transpose(mat([2 ,2]))
x=zeros([2,1])
print 'intial v & w:\n',x,'\n'
x_1=zeros([1,2])
for k in range(0,26):
x_1=p*x+(S**-1)*b
x=x_1
print 'k=',k
print 'v(k+1) & w(k+1)=',x_1,'\n'

intial v & w:
[[ 0.]
[ 0.]]

k= 0
v(k+1) & w(k+1)= [[ 1.]
[ 1.]]

k= 1
v(k+1) & w(k+1)= [[ 1.5]
[ 1.5]]

k= 2
v(k+1) & w(k+1)= [[ 1.75]
[ 1.75]]

k= 3
v(k+1) & w(k+1)= [[ 1.875]
[ 1.875]]

k= 4
v(k+1) & w(k+1)= [[ 1.9375]
[ 1.9375]]

k= 5
v(k+1) & w(k+1)= [[ 1.96875]
[ 1.96875]]

k= 6
v(k+1) & w(k+1)= [[ 1.984375]
[ 1.984375]]

k= 7
v(k+1) & w(k+1)= [[ 1.9921875]
[ 1.9921875]]

k= 8
v(k+1) & w(k+1)= [[ 1.99609375]
[ 1.99609375]]

k= 9
v(k+1) & w(k+1)= [[ 1.99804688]
[ 1.99804688]]

k= 10
v(k+1) & w(k+1)= [[ 1.99902344]
[ 1.99902344]]

k= 11
v(k+1) & w(k+1)= [[ 1.99951172]
[ 1.99951172]]

k= 12
v(k+1) & w(k+1)= [[ 1.99975586]
[ 1.99975586]]

k= 13
v(k+1) & w(k+1)= [[ 1.99987793]
[ 1.99987793]]

k= 14
v(k+1) & w(k+1)= [[ 1.99993896]
[ 1.99993896]]

k= 15
v(k+1) & w(k+1)= [[ 1.99996948]
[ 1.99996948]]

k= 16
v(k+1) & w(k+1)= [[ 1.99998474]
[ 1.99998474]]

k= 17
v(k+1) & w(k+1)= [[ 1.99999237]
[ 1.99999237]]

k= 18
v(k+1) & w(k+1)= [[ 1.99999619]
[ 1.99999619]]

k= 19
v(k+1) & w(k+1)= [[ 1.99999809]
[ 1.99999809]]

k= 20
v(k+1) & w(k+1)= [[ 1.99999905]
[ 1.99999905]]

k= 21
v(k+1) & w(k+1)= [[ 1.99999952]
[ 1.99999952]]

k= 22
v(k+1) & w(k+1)= [[ 1.99999976]
[ 1.99999976]]

k= 23
v(k+1) & w(k+1)= [[ 1.99999988]
[ 1.99999988]]

k= 24
v(k+1) & w(k+1)= [[ 1.99999994]
[ 1.99999994]]

k= 25
v(k+1) & w(k+1)= [[ 1.99999997]
[ 1.99999997]]



## Ex:7.4.2 Pg: 238¶

In [2]:
from __future__ import division
from numpy import mat,transpose,zeros
from numpy.random import rand
from numpy.linalg import inv
A=mat([[2, -1],[-1, 2]])
S=mat([[2, 0],[-1, 2]])
T=mat([[0, 1],[0, 0]])
b=rand(2,1)
p=inv(S)*T
x=zeros([2,1])
print 'intial v & w:',x
x_1=zeros([1,2])
for k in range(0,26):
x_1=p*x+inv(S)*b
x=x_1
print 'k=\n',k
print 'v(k+1) & w(k+1)=\n',x_1

intial v & w: [[ 0.]
[ 0.]]
k=
0
v(k+1) & w(k+1)=
[[ 0.10887353]
[ 0.53877511]]
k=
1
v(k+1) & w(k+1)=
[[ 0.37826108]
[ 0.67346888]]
k=
2
v(k+1) & w(k+1)=
[[ 0.44560797]
[ 0.70714233]]
k=
3
v(k+1) & w(k+1)=
[[ 0.46244469]
[ 0.71556069]]
k=
4
v(k+1) & w(k+1)=
[[ 0.46665387]
[ 0.71766528]]
k=
5
v(k+1) & w(k+1)=
[[ 0.46770617]
[ 0.71819143]]
k=
6
v(k+1) & w(k+1)=
[[ 0.46796924]
[ 0.71832296]]
k=
7
v(k+1) & w(k+1)=
[[ 0.46803501]
[ 0.71835585]]
k=
8
v(k+1) & w(k+1)=
[[ 0.46805145]
[ 0.71836407]]
k=
9
v(k+1) & w(k+1)=
[[ 0.46805556]
[ 0.71836612]]
k=
10
v(k+1) & w(k+1)=
[[ 0.46805659]
[ 0.71836664]]
k=
11
v(k+1) & w(k+1)=
[[ 0.46805685]
[ 0.71836676]]
k=
12
v(k+1) & w(k+1)=
[[ 0.46805691]
[ 0.7183668 ]]
k=
13
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
14
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
15
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
16
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
17
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
18
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
19
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
20
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
21
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
22
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
23
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
24
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]
k=
25
v(k+1) & w(k+1)=
[[ 0.46805693]
[ 0.71836681]]