Skip to content

Commit 6c9bb74

Browse files
author
dendriny
committed
Initial commit
0 parents  commit 6c9bb74

7 files changed

+341
-0
lines changed

CW1.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
# import scipy.linalg
3+
import utilities
4+
5+
# data1 = np.genfromtxt('./readings.csv', delimiter=',', dtype=float)
6+
# # data2 = np.genfromtxt('./readings2.csv', delimiter=',', dtype=float)
7+
# print(np.shape(data1))
8+
# light = data1[:, 0]
9+
# temp = data1[:, 1]
10+
11+
m, n = (5, 5)
12+
np.random.seed(1)
13+
An = np.random.rand(m, n).astype(np.float_) #+ 1j * np.random.rand(m, n)
14+
qn, rn = np.linalg.qr(An)
15+
qrn = qn @ rn
16+
17+
18+
# print(np.array_equal(np.conj(np.transpose(qn)) @ qn, qn @ np.conj(np.transpose(qn))))
19+
# print(np.array_equal(np.identity(qn.shape[0]), qn.T.conj() @ qn))
20+
# print(np.absolute(A - qn @ rn).sum())
21+
# print(qn.T.conj() @ qn)
22+
23+
np.random.seed(1)
24+
A = np.random.rand(m, n).astype(np.float_) #+ 1j * np.random.rand(m, n)
25+
q, r = utilities.householder_qr(A)
26+
np.random.seed(1)
27+
A = np.random.rand(m, n).astype(np.float_)
28+
qr = q @ r
29+
30+
# print(A)
31+
# print(qr)
32+
# print(qrn)

Tests/__init__.py

Whitespace-only changes.

Tests/test_norm.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest import TestCase
2+
from utilities import norm, qr
3+
import numpy as np
4+
5+
6+
class TestNorm(TestCase):
7+
def test_norm(self):
8+
v = np.array([[5.], [4.], [1.]])
9+
actual = norm(v)
10+
expected = np.sqrt(5.**2 + 4.**2 + 1.)
11+
self.assertEqual(expected, actual)
12+
13+
def test_qr_real(self):
14+
m, n = (8, 8)
15+
np.random.seed(1)
16+
a = np.random.rand(m, n).astype(np.float_)
17+
q, r = qr(a)
18+
np.random.seed(1)
19+
a = np.random.rand(m, n).astype(np.float_)
20+
self.assertAlmostEqual(0, np.absolute(a - q @ r).sum())
21+
self.assertAlmostEqual(np.abs(1), np.linalg.det(q))
22+
self.assertAlmostEqual(0, np.absolute(q.T @ q - q @ q.T).sum())
23+
self.assertAlmostEqual(0, np.absolute(np.identity(q.shape[0]) - q @ q.T).sum())
24+
25+
def test_qr_complex(self):
26+
m, n = (8, 8)
27+
np.random.seed(1)
28+
a = np.random.rand(m, n).astype(np.complex_) + 1j * np.random.rand(m, n)
29+
q, r = qr(a)
30+
np.random.seed(1)
31+
a = np.random.rand(m, n).astype(np.complex_) + 1j * np.random.rand(m, n)
32+
self.assertAlmostEqual(0, np.absolute(a - q @ r).sum())
33+
self.assertAlmostEqual(np.abs(1), np.linalg.det(q))
34+
self.assertAlmostEqual(0, np.absolute(q.T.conj() @ q - q @ q.T.conj()).sum())
35+
self.assertAlmostEqual(0, np.absolute(np.identity(q.shape[0]) - q @ q.T.conj()).sum())

project1.pdf

65.6 KB
Binary file not shown.

readings.csv

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
0.327236921472561,0.283677779103201
2+
0.960771516517218,0.063541726109851
3+
0.140053631957261,0.345452271030279
4+
0.760058704082313,-0.055682593372188
5+
0.697569362846686,-0.021785230457089
6+
0.199775359431029,0.32454818756784
7+
0.011062418404475,0.368660355924264
8+
0.302710970123795,0.290305193957731
9+
0.566412682153102,0.091827377088458
10+
0.051214319806592,0.365258872315448
11+
0.251858361865945,0.31831520346627
12+
0.206966588898727,0.32987144703156
13+
0.105811931752695,0.356390783103961
14+
0.186628128867756,0.329913826335362
15+
0.232029867186185,0.331400466374657
16+
0.688060593313539,-0.012795565473385
17+
0.599352306305329,0.072699064424155
18+
0.291761322950986,0.299860270275053
19+
0.657866158699429,0.014091888450643
20+
0.347945431443574,0.26315307987439
21+
0.823694332006686,-0.071741935886398
22+
0.77828367991118,-0.061095280078421
23+
0.326815940425455,0.282329856534119
24+
0.029859028514561,0.365296663286147
25+
0.314771501006191,0.277363759912849
26+
0.704677484099349,-0.032456353555839
27+
0.280344136357949,0.305230128210183
28+
0.231997358301959,0.331742853599712
29+
0.117709478874656,0.363393114450314
30+
0.756823723277037,-0.06407491918234
31+
0.983212584298541,0.120001400111988
32+
0.357632821142134,0.268995574490696
33+
0.005545860444192,0.37583065542404
34+
0.895516920674991,-0.029793190791843
35+
0.293119523122116,0.294402008999735
36+
0.614668646541226,0.056952662018271
37+
0.680999007938701,-0.010927443717844
38+
0.407416034864057,0.222859827425507
39+
0.134971957456316,0.346417487136992
40+
0.52484072374052,0.134236435851715
41+
0.666621230375793,0.012886253107954
42+
0.263438809880205,0.301025301249367
43+
0.769449479583117,-0.062151440425392
44+
0.433017741661292,0.206703161269848
45+
0.82601761264045,-0.066669241140935
46+
0.972588923529043,0.083939499333047
47+
0.652037147251497,0.00704352967609
48+
0.286864928605457,0.290788973811894
49+
0.162613112788719,0.345005291314953
50+
0.791770747838646,-0.073997928508913
51+
0.731279879100578,-0.040764943401419
52+
0.44343173208048,0.2077072137054
53+
0.200488768631665,0.336367156415803
54+
0.533408350087565,0.12941285087277
55+
0.728092033231586,-0.042690956531989
56+
0.160890461984303,0.335946089762146
57+
0.442109641560032,0.196962415072168
58+
0.29128390023903,0.307863723758412
59+
0.225899699468038,0.317756803849928
60+
0.712057843993492,-0.039980915737272
61+
0.773644819906793,-0.071942478321544
62+
0.774957930170735,-0.065116448640676
63+
0.804028217436453,-0.062210222500167
64+
0.072953510092216,0.357126404168306
65+
0.430989700098076,0.205517298910076
66+
0.245707353004012,0.313594685687975
67+
0.102631297099393,0.366222592178095
68+
0.29622116674514,0.295186735625476
69+
0.494959267814477,0.160735582546811
70+
0.555278733231525,0.109442837106137
71+
0.066191404374786,0.370225498069228
72+
0.471422616918895,0.174959575802075
73+
0.112996423727603,0.354995685996582
74+
0.435440976798092,0.200068527188344
75+
0.48426424419151,0.172871876784774
76+
0.542305580296181,0.107157459526962
77+
0.242587459766387,0.314034628074942
78+
0.329998830699741,0.281031587554389
79+
0.10559555167561,0.357563639965701
80+
0.709994625641266,-0.039234218929754
81+
0.507789690681937,0.143906563220508
82+
0.882306732399738,-0.048543612432113
83+
0.814013727349188,-0.064182797003057
84+
0.956216380607,0.059338882482015
85+
0.179641927173164,0.342844979643053
86+
0.794492369065901,-0.061739345773488
87+
0.77906487650133,-0.060398367190287
88+
0.491668518982105,0.15440424657177
89+
0.306065314316323,0.299930422894404
90+
0.683293160048005,-0.000357067767217
91+
0.983089897761812,0.111687728153603
92+
0.345356252332413,0.271693663299734
93+
0.150511609511496,0.344362298441378
94+
0.257563046030811,0.307065983459631
95+
0.938028185077149,0.009209615473034
96+
0.122967977453728,0.359617622928421
97+
0.769856733518185,-0.054152821088222
98+
0.491901724918076,0.167126023919534
99+
0.353227917626708,0.264873215908216
100+
0.265903935584717,0.302165470551137

0 commit comments

Comments
 (0)