Attempt:Orthogonal projection of $\mathbb{C}^3$ onto image of linear operator [closed]
I want to compute the orthogonal projection of $\mathbb{C}^3$ onto the image of $T(x,y,z)=(x-iy+iz,ix-z,2y).$ I know that $\text{im}(T)=\text{span}{(1,i,0),(-i,0,2)}.$ Sor far i have:
#Base estandar de C^3, denotada B
e1 = vector([1, 0, 0])
e2 = vector([0, 1, 0])
e3 = vector([0, 0, 1])
#Base de im(T)
b1=vector([1,i,0])
b2=vector([-i,0,2])
#Aplicar Gram-Schmidt a b1=u1 y b2 para obtener base ortogonal
u2 = b2 - (b2.dot_product(b1.conjugate()) / b1.dot_product(b1.conjugate())) * b1
# Simplificar el vector u2
u2_clean = vector([SR(entry).simplify() for entry in u2])
# Mostrar base ortogonal de im(T)
print("Vectores u1 y u2 de la base ortogonal:")
show(b1,u2_clean)
#Calcular las normas de b1=u1 y de u2
n_u1= sqrt(b1.dot_product(b1.conjugate()))
n_u2=sqrt(u2_clean.dot_product(u2_clean.conjugate()))
#Construir y mostrar los vectores w1 y w2 de la base ortonormal
w1 = b1/n_u1
w2 = u2_clean/n_u2
print("Vectores w1 y w2 de la base ortonormal:")
show(w1,w2)
#Definir vector simbólico arbitrario
a,b,c=var("a,b,c")
v = vector([a,b,c])
#Calcular la proyección ortogonal de C^3 sobre im(T)
P_imT = (v.dot_product(w1.conjugate()))*w1 + (v.dot_product(w2.conjugate()))*w2
print("P(a,b,c)=")
show(P_imT)
# Evaluar la proyección en la base estándar
P_e1 = P_imT.subs({a: 1, b: 0, c: 0})
P_e2 = P_imT.subs({a: 0, b: 1, c: 0})
P_e3 = P_imT.subs({a: 0, b: 0, c: 1})
# Mostrar los resultados de P(ei)
print("Proyección de e1: ", P_e1)
print("Proyección de e2: ", P_e2)
print("Proyección de e3: ", P_e3)
#Evaluar P(T(ei))
P_Te1 = P_imT.subs({a: 1, b: i, c: 0})
P_Te2 = P_imT.subs({a: -i, b: 0, c: 2})
P_Te3 = P_imT.subs({a: i,b: -1, c: 0})
print("Evaluando P(T(e1)), P(T(e2)), P(T(e3)):")
show(P_Te1,P_Te2,P_Te3)
#Construir matriz [P]_B a partir de P(ei)
P_B = Matrix([[5/9,
-4/9*I, -2/9*I],[4/9*I, 5/9, 2/9],[2/9*I, -2/9, 8/9]])
print("[P]_B=")
show(P_B)
#verificar que la base ortogonal y ortonormal de verdad sean ortogonales.
show(b1.dot_product(u2_clean.conjugate()))
show(w1.dot_product(w2.conjugate()))
My concerns here are the I don't know if the formula for P(a,b,c) I found is correct, and subsequently, why the "projection" matrix [P]_B is not idempotent to begin with. I deleted the line in which i computed ([P]_B)^2 but it was not idempotent, so clearly it cannot be an orthogonal projection if it's not a projection to begin with. What did I do wrong here?
Note: I know there might be built-in functions to compute the norm or to apply Gram-Schmidt, but I would really like to do this without recurring to those options. Also, the vectors w1 and w2 of the orthonormal basis are indeed orthogonal to each other, so I have know idea where it went wrong.