In [1]:
eye(5)
Out[1]:
In [8]:
# 1-indexed!!!
eye(5)[1, 1]
Out[8]:
In [12]:
eye(5)[1:2, 1:2]
Out[12]:
In [15]:
eye(5)[1:3, :]
Out[15]:
In [16]:
eye(5)[1:3, 4]
Out[16]:
In [22]:
x = repeat([1], outer=[3])
Out[22]:
In [28]:
*(x, transpose(x))
Out[28]:
In [33]:
e = eye(4) + 3 * *([0, 0, 0, 1], transpose([1, 0, 0, 0]))
e
Out[33]:
https://people.csail.mit.edu/jsolomon/share/book/numerical_book.pdf
Example 3.3 Page 54
In [96]:
A = [[0 1 -1]; [3 -1 1]; [1 1 -2]]
Out[96]:
In [87]:
# permute
P = [[0 0 1]; [1 0 0]; [0 1 0]]
Out[87]:
In [88]:
e3_ = repeat([0], outer=[3, 1])
e3_[3, 1] = 1
e1_T = repeat([0], outer=[1, 3])
e1_T[1, 1] = 1
E1 = eye(3) - 3 * *(e3_, e1_T)
Out[88]:
In [64]:
e2_T = repeat([0], outer=[1, 3])
e2_T[1, 2] = 1
E2 = eye(3) + 4 * *(e3_, e2_T)
Out[64]:
In [66]:
S = Diagonal([1,1,1/3])
Out[66]:
In [72]:
e1_ = repeat([0], outer=[3, 1])
e1_[1, 1] = 1
e3_T = repeat([0], outer=[1, 3])
e3_T[1, 3] = 1
E3 = eye(3) + 2 * *(e1_, e3_T)
Out[72]:
In [73]:
e2_ = repeat([0], outer=[3, 1])
e2_[2, 1] = 1
E4 = eye(3) + *(e2_, e3_T)
Out[73]:
In [76]:
e3_T
Out[76]:
In [77]:
*(e1_, e3_T)
Out[77]:
In [89]:
E5 = eye(3) - *(e1_, e2_T)
Out[89]:
In [91]:
A_inv = E5 * E4 * E3 * S * E2 * E1 * P
Out[91]:
In [102]:
A_inv
Out[102]:
In [103]:
b = [-1, 4, -3]
Out[103]:
In [106]:
# Solution
A_inv * b
Out[106]:
In [105]:
# Identity
A_inv * A
Out[105]:
In [114]:
m = [[1 2 3]; [4 5 6]; [7 8 9]]
Out[114]:
In [115]:
l, u, p = lu(A)
Out[115]:
In [116]:
l
Out[116]:
In [117]:
u
Out[117]:
In [118]:
p
Out[118]: