Question: v 1 = [ 2 1 1 ] , v 2 = [ 1 1 0 ] , v 3 = [ 0 1 1
v
v
v
what is wrong with my code, i keep getting: Orthonormalized Vectors Q:eeeeeeeee When i should get vector vector and vector I included an image of the the expected numbers should be given these certain vectors.
this is my code: import numpy as np
# Define the input vectors
v nparray
v nparray
v nparray
# Combine the vectors into a matrix where each column is a vector
V npcolumnstackv v v
def gramschmidtV:
# Input: V is a set of vectors stored as columns in a matrix
V Vastypenpfloat# Ensure float precision
n k Vshape
Q npzeroslikeV# Matrix to store the orthonormalized vectors
for j in rangek:
vj V: jcopy# Work with the jth vector
for i in rangej:
qi Q: i
s npdotvj qi# s vj qi
vj vj s qi # vj vj s qi
normvj nplinalg.normvj
if normvj e: # Normalize to avoid division by zero
Q: j vj normvj # vj vj vj
return Q
def verifyorthonormalityQ:
# Verify magnitudes should be close to
for idx, q in enumerateQT:
magnitude nplinalg.normq
printfMagnitude of vector idxmagnitude:f
print
# Verify dot products between different vectors should be close to
k Qshape
for i in rangek:
for j in rangei k:
dotproduct npdotQ: i Q: j
printfDot product of vectors i and j: dotproduct:f
# Perform GramSchmidt orthonormalization
Q gramschmidtV
# Display the orthonormalized vectors
printOrthonormalized Vectors Q:
printQ
# Verify orthonormality
print
Running verification function:"
verifyorthonormalityQ
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
