Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Last active January 23, 2017 17:31
Show Gist options
  • Save manashmandal/d16829027428340aaf2d10412e8b40e9 to your computer and use it in GitHub Desktop.
Save manashmandal/d16829027428340aaf2d10412e8b40e9 to your computer and use it in GitHub Desktop.
Linear Algebra : Introduction To Linear Algebra PSET : https://ocw.mit.edu/courses/mathematics/18-06-linear-algebra-spring-2010/assignments/
import numpy as np
from scipy import linalg
from __future__ import print_function
K = linalg.toeplitz([-2, 1, 0, 0, 0, 0])
P, L, U = linalg.lu(K)
print (linalg.inv(L))
## Output:
#[[ 1. 0. 0. 0. -0. -0. ]
# [ 0.5 1. 0. 0. -0. -0. ]
# [ 0.33333333 0.66666667 1. 0. -0. -0. ]
# [ 0.25 0.5 0.75 1. -0. -0. ]
# [ 0.2 0.4 0.6 0.8 1. -0. ]
# [ 0.16666667 0.33333333 0.5 0.66666667 0.83333333 1. ]]
from __future__ import print_function
import numpy as np
from scipy import linalg
SevenKInv = np.array([
[6, 5, 4, 3, 2, 1],
[5, 10, 8, 6, 4, 2],
[4, 8, 12, 9, 6, 3],
[3, 6, 9, 12, 8, 4],
[2, 4, 6, 8, 10, 5],
[1, 2, 3, 4, 5, 6]
])
K = linalg.toeplitz(np.array([2, -1, 0, 0, 0, 0]))
print (SevenKInv.dot(K))
"""
Output:
[[7 0 0 0 0 0]
[0 7 0 0 0 0]
[0 0 7 0 0 0]
[0 0 0 7 0 0]
[0 0 0 0 7 0]
[0 0 0 0 0 7]]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment