Created
December 27, 2020 16:19
-
-
Save pqlx/3a50c0acad68a42d62b94a053be0073b to your computer and use it in GitHub Desktop.
Gram-Schmidt algorithm for finding orthogonal basis U in vector space Φ, given a basis V in vector space Φ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def proj(u, v): | |
return np.multiply(u, (np.inner(u, v)/np.inner(u, u))) | |
def orthogonal_basis(*V): | |
"""Uses the Gram-Schmidt algorithm for finding an orthogonal basis of V""" | |
U = [None] * len(V) | |
for k in range(len(V)): | |
U[k] = V[k] - sum(proj(U([j], V[k]) for j in range(k)) | |
return U |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment