Skip to content

Commit 8c6e5aa

Browse files
author
sushmit
committed
Sr:adding files for chapter 9
1 parent 358c544 commit 8c6e5aa

File tree

7 files changed

+597
-0
lines changed

7 files changed

+597
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Example 9.6.7\n",
12+
"from vec import *\n",
13+
"from mat import *\n",
14+
"from matutil import *\n",
15+
"from vecutil import *\n",
16+
"from GF2 import one\n",
17+
"from orthogonalization import *\n",
18+
"from orthonormalization import *\n",
19+
"import independence\n",
20+
"from QR import *"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 2,
26+
"metadata": {
27+
"collapsed": false
28+
},
29+
"outputs": [
30+
{
31+
"name": "stdout",
32+
"output_type": "stream",
33+
"text": [
34+
"[Vec({0, 1, 2, 3},{0: -4, 1: 3, 2: 1, 3: -2}), Vec({0, 1, 2, 3},{0: 0.5333333333333332, 1: 0.10000000000000009, 2: 2.3666666666666667, 3: 0.2666666666666666}), Vec({0, 1, 2, 3},{0: 0.41899441340782123, 1: 0.3910614525139665, 2: -0.07821229050279327, 3: -0.29050279329608936}), Vec({0, 1, 2, 3},{0: -1.1102230246251565e-16, 1: 0.33333333333333315, 2: -0.06666666666666665, 3: 0.46666666666666673}), Vec({0, 1, 2, 3},{0: 5.5511151231257815e-18, 1: -4.163336342344337e-17, 2: -1.9255430583342559e-16, 3: 0.0}), Vec({0, 1, 2, 3},{0: 2.1094237467877978e-16, 1: 2.220446049250313e-16, 2: -1.3877787807814457e-17, 3: -2.220446049250313e-16})]\n",
35+
"\n",
36+
" 0 1 2 3\n",
37+
"-----------------\n",
38+
" -120 -30 -90 -60\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"L = [list2vec(v) for v in [[8,-2,2], [0,3,3], [1,0,0], [0,1,0], [0,0,1]]]\n",
44+
"\n",
45+
"Lstar = orthogonalize(L)\n",
46+
"\n",
47+
"#print(Lstar)\n",
48+
"# Problem 9.11.1\n",
49+
"\n",
50+
"U1 = [list2vec(v) for v in [[0,0,3,2],[1,2,-3,-1],[1,2,0,1],[3,1,0,-1],[-1,-2,3,1]]]\n",
51+
"Lstar = orthogonalize(U1)\n",
52+
"\n",
53+
"#print(Lstar[1])\n",
54+
"\n",
55+
"\n",
56+
"#independence.is_independent(U1) \n",
57+
"\n",
58+
"U2 = [list2vec(v) for v in [[3,0,1],[1,0,0],[1,0,1]]]\n",
59+
"Lstar = orthogonalize(U2)\n",
60+
"#print(Lstar[2])\n",
61+
"\n",
62+
"U3 = [list2vec(v) for v in [[-4,3,1,-2],[-2,2,3,-1],[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]]\n",
63+
"Lstar = orthogonalize(U3)\n",
64+
"print(Lstar)\n",
65+
"\n",
66+
"\n",
67+
"# Problem 9.11.3\n",
68+
"\n",
69+
"#A = [list2vec(v) for v in [[-4,0],[-1,4],[-3,0],[-2,-1]]]\n",
70+
"\n",
71+
"A = [list2vec(v) for v in [[-4,-1,-3,-2],[0,4,0,-1],[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]]\n",
72+
"\n",
73+
"Basis = orthogonalize(A)\n",
74+
"print((Basis[0]*Basis[0]) *Basis[0])\n"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {
81+
"collapsed": false,
82+
"scrolled": false
83+
},
84+
"outputs": [],
85+
"source": [
86+
"# Problem 9.11.9\n",
87+
"D = {'a','b','c','d'}\n",
88+
"L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]\n",
89+
"for v in orthonormalize(L): print(v)\n",
90+
"\n",
91+
"# Problem 9.11.10 \n",
92+
" \n",
93+
"# U2 = [list2vec(v) for v in [[0.73, 0.55, 0.18, 0.37], [0.19, 0.40, -0.57, -0.69], [0.53, -0.65, -0.51, 0.18]]]\n",
94+
"# #Lstar = orthogonalize(U2)\n",
95+
"\n",
96+
"# U3 = 1\n",
97+
"\n",
98+
"L = [list2vec(v) for v in [[4,3,1,2],[8,9,-5,-5],[10,1,-1,5]]]\n",
99+
"\n",
100+
"print(coldict2mat(L))\n",
101+
"\n",
102+
"#Qlist_unormalized = aug_orthogonalize(L)[0]\n",
103+
"#Rlist1 = aug_orthogonalize(L)[1]\n",
104+
"# print(coldict2mat(Qlist[1]))\n",
105+
"\n",
106+
"# print(mat2rowdict(coldict2mat(Qlist[1])))\n",
107+
"\n",
108+
"# print(Qlist[0]*Qlist[0])\n",
109+
"\n",
110+
"# print(2*mat2rowdict(coldict2mat(RList))[0])\n",
111+
"\n",
112+
"Qlist,Rlist = aug_orthonormalize(L)\n",
113+
"print(coldict2mat(Qlist))\n",
114+
"\n",
115+
"print(coldict2mat(Rlist))\n",
116+
"\n",
117+
"\n",
118+
"print(coldict2mat(Qlist)*coldict2mat(Rlist))\n",
119+
"\n",
120+
"# problem 9.11.12\n",
121+
"L = [list2vec(v) for v in [[6,2,3],[6,0,3]]]\n",
122+
"print(coldict2mat(L))\n",
123+
"\n",
124+
"Qlist,Rlist = aug_orthonormalize(L)\n",
125+
"print(coldict2mat(Qlist))\n",
126+
"\n",
127+
"print(coldict2mat(Rlist))\n",
128+
"print(coldict2mat(Qlist)*coldict2mat(Rlist))\n",
129+
"\n",
130+
"# problem 9.11.12\n",
131+
"L = [list2vec(v) for v in [[2,2,1],[3,1,1]]]\n",
132+
"print(coldict2mat(L))\n",
133+
"\n",
134+
"Qlist,Rlist = aug_orthonormalize(L)\n",
135+
"print(coldict2mat(Qlist))\n",
136+
"\n",
137+
"print(coldict2mat(Rlist))\n"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {
144+
"collapsed": false
145+
},
146+
"outputs": [],
147+
"source": [
148+
"A=Mat(({'a','b','c'},{'A','B'}), {('a','A'):-1, ('a','B'):2, ('b','A'):5, ('b','B'):3,('c','A'):1, ('c','B'):-2})\n",
149+
"\n",
150+
"print(A)\n",
151+
"Q= factor(A)\n",
152+
"\n",
153+
"print(Q)"
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"metadata": {
160+
"collapsed": false
161+
},
162+
"outputs": [],
163+
"source": [
164+
"# Problem 9.11.10 \n",
165+
" \n",
166+
"# U2 = [list2vec(v) for v in [[0.73, 0.55, 0.18, 0.37], [0.19, 0.40, -0.57, -0.69], [0.53, -0.65, -0.51, 0.18]]]\n",
167+
"# #Lstar = orthogonalize(U2)\n",
168+
"\n",
169+
"# U3 = 1\n",
170+
"\n",
171+
"L = [list2vec(v) for v in [[4,3,1,2],[8,9,-5,-5],[10,1,-1,5]]]\n",
172+
"\n",
173+
"print(coldict2mat(L))\n",
174+
"\n",
175+
"#Qlist_unormalized = aug_orthogonalize(L)[0]\n",
176+
"#Rlist1 = aug_orthogonalize(L)[1]\n",
177+
"# print(coldict2mat(Qlist[1]))\n",
178+
"\n",
179+
"# print(mat2rowdict(coldict2mat(Qlist[1])))\n",
180+
"\n",
181+
"# print(Qlist[0]*Qlist[0])\n",
182+
"\n",
183+
"# print(2*mat2rowdict(coldict2mat(RList))[0])\n",
184+
"\n",
185+
"Qlist,Rlist = aug_orthonormalize(L)\n",
186+
"print(coldict2mat(Qlist))\n",
187+
"\n",
188+
"print(Qlist)\n",
189+
"\n",
190+
"print(mat2coldict(rowdict2mat(Rlist)))\n",
191+
"dict2list(mat2coldict(rowdict2mat(Rlist)),range(len(Qlist)))\n"
192+
]
193+
}
194+
],
195+
"metadata": {
196+
"kernelspec": {
197+
"display_name": "Python 3",
198+
"language": "python",
199+
"name": "python3"
200+
},
201+
"language_info": {
202+
"codemirror_mode": {
203+
"name": "ipython",
204+
"version": 3
205+
},
206+
"file_extension": ".py",
207+
"mimetype": "text/x-python",
208+
"name": "python",
209+
"nbconvert_exporter": "python",
210+
"pygments_lexer": "ipython3",
211+
"version": "3.5.1"
212+
}
213+
},
214+
"nbformat": 4,
215+
"nbformat_minor": 0
216+
}

0 commit comments

Comments
 (0)