Untitled
unknown
plain_text
a year ago
584 B
7
Indexable
jejejjdjd
import numpy as np
def gram_schmidt_qr(A):
n = A.shape[0]
Q = np.zeros_like(A, dtype=np.float64)
R = np.zeros((n, n))
for i in range(n):
v = A[:, i]
for j in range(i):
R[j, i] = np.dot(Q[:, j], A[:, i])
v = v - R[j, i] * Q[:, j]
R[i, i] = np.linalg.norm(v)
Q[:, i] = v / R[i, i]
return Q, R
# Example Usage
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 10]], dtype=np.float64)
Q, R = gram_schmidt_qr(A)
print("Matrix Q (Orthogonal):")
print(Q)
print("\nMatrix R (Upper Triangular):")
print(R)Editor is loading...
Leave a Comment