<<VilGebra`

Proyección ortogonal: calcular la proyección de v sobre el subespacio W.

1. Sea v = (3, 1, 4) y W = Gen{ (1,1,0), (1,0,1) } en ℝ^3.

v={3,1,4};
w1={1,1,0};
w2={1,0,1};
PrOt[v,{w1,w2}]

2. Sea v = (2, 3, 1, 2) y W = Gen{ (1,0,1,0), (0,1,0,1) } en ℝ^4.

v={2,3,1,2};
w1={1,0,1,0};
w2={0,1,0,1};
PrOt[v,{w1,w2}]

3. Sea v = (5, -1, 2) y W = Gen{ (1,2,1) } en ℝ^3.

v={5,-1,2};
w={1,2,1};
PrOt[v,{w}]

4. Sea v = (1, 2, -1, 3, 0) y W = Gen{ (1,0,1,0,0), (0,1,1,1,0) } en ℝ^5.

v={1,2,-1,3,0};
w1={1,0,1,0,0};
w2={0,1,1,1,0};
PrOt[v,{w1,w2}]

5. Sea v = (4, -2, 1, 3) y W = Gen{ (2,1,0,0), (1,1,1,0), (0,1,1,1) } en ℝ^4.

v={4,-2,1,3};
w1={2,1,0,0};
w2={1,1,1,0};
w3={0,1,1,1};
PrOt[v,{w1,w2,w3}]

6. Sea v = (3,0,2,1) y W = Gen{ (1,1,1,1), (1,-1,0,0) } en ℝ^4.

v={3,0,2,1};
PrOt[v,{{-1,-1,0,2},{-1,-1,2,0}}]

7. Sea v = (1,1,1,1,1) y W = Gen{ (1,0,0,1,0), (0,1,0,0,1) } en ℝ^5.

v={1,1,1,1,1};
w1={1,0,0,1,0};
w2={0,1,0,0,1};
PrOt[v,{w1,w2}]

8. Sea v = (2, -1, 3, 0, 4, 1) y W = Gen{ (1,1,0,0,0,0), (0,0,1,1,0,0), (0,0,0,0,1,1) } en ℝ^6.

v={2,-1,3,0,4,1};
g1={1,1,0,0,0,0};
g2={0,0,1,1,0,0};
g3={0,0,0,0,1,1};
PrOt[v,{g1,g2,g3}]

9. Sea v = (1, -2, 0, 3, -1, 2) y W el subespacio de R^6 definido por las ecuaciones: x1 + x2 = 0 y x3 + x4 = 0.

v={1,-2,0,3,-1,2};
e1={1,-1,0,0,0,0};
e2={0,0,1,-1,0,0};
e3={0,0,0,0,1,0};
e4={0,0,0,0,0,1};
PrOt[v,{e1,e2,e3,e4}]

10. Sea v = (2, 1, 3, -1, 0, 2, 1) y W el subespacio de R^7 definido por las ecuaciones: x1 + x2 = 0  y  x3 + x4 + x5 = 0.

v={2,1,3,-1,0,2,1};
e1={1,-1,0,0,0,0,0};   
e2={0,0,1,0,-1,0,0};   
e3={0,0,0,1,-1,0,0}; 
e4={0,0,0,0,0,1,0};    
e5={0,0,0,0,0,0,1};  
PrOt[v,{e1,e2,e3,e4,e5}]

Conjuntos ortogonales u ortonormales

1. { (1/√2)(1,1,0), (1/√2)(1,-1,0), (0,0,1) }

u1=(1/Sqrt[2]) {1,1,0};
u2=(1/Sqrt[2]) {1,-1,0};
u3={0,0,1};
Table[ui.uj,{ui,{u1,u2,u3}},{uj,{u1,u2,u3}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

2. {(2,1,0), (1,-2,0), (0,0,3)}

u1={2,1,0};
u2={1,-2,0};
u3={0,0,3};
Table[ui.uj,{ui,{u1,u2,u3}},{uj,{u1,u2,u3}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

3. {(1,2,1), (1,0,-1), (2,-1,0)}

u1={1,2,1};
u2={1,0,-1};
u3={2,-1,0};
Table[ui.uj,{ui,{u1,u2,u3}},{uj,{u1,u2,u3}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

4. {(1/√3)(1,1,1), (1/√2)(1,-1,0), (1/√6)(1,1,-2)}

u1=(1/Sqrt[3])*{1,1,1};
u2=(1/Sqrt[2])*{1,-1,0};
u3=(1/Sqrt[6])*{1,1,-2};
Table[ui.uj,{ui,{u1,u2,u3}},{uj,{u1,u2,u3}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

5. {(1,0,1,0), (0,1,0,1), (1,0,-1,0), (0,1,0,-1)}

u1={1,0,1,0};
u2={0,1,0,1};
u3={1,0,-1,0};
u4={0,1,0,-1};
Table[ui.uj,{ui,{u1,u2,u3,u4}},{uj,{u1,u2,u3,u4}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

6. {1, Cos[x], Sin[x]}

f1=1;
f2=Cos[x];
f3=Sin[x];
inner[p_,q_]:=Integrate[p*q,{x,-Pi,Pi}];
dot11=inner[f1,f1]//Simplify
dot12=inner[f1,f2]//Simplify
dot13=inner[f1,f3]//Simplify
dot21=inner[f2,f1]//Simplify
dot22=inner[f2,f2]//Simplify
dot23=inner[f2,f3]//Simplify
dot31=inner[f3,f1]//Simplify
dot32=inner[f3,f2]//Simplify
dot33=inner[f3,f3]//Simplify
Gram={{dot11,dot12,dot13},{dot21,dot22,dot23},{dot31,dot32,dot33}}//Simplify
NormsSq={dot11,dot22,dot33}//Simplify
isOrthogonal=And@@Flatten[Table[If[i==j,True,Gram[[i,j]]==0],{i,3},{j,3}]]
isOrthonormal=And@@Flatten[Table[Gram[[i,j]]==If[i==j,1,0],{i,3},{j,3}]]
{Gram,NormsSq,isOrthogonal,isOrthonormal}

7. {(1/2)(1,1,1,1), (1/2)(1,1,-1,-1), (1/2)(1,-1,1,-1), (1/2)(1,-1,-1,1)}

u1=(1/2)*{1,1,1,1};
u2=(1/2)*{1,1,-1,-1};
u3=(1/2)*{1,-1,1,-1};
u4=(1/2)*{1,-1,-1,1};
Table[ui.uj,{ui,{u1,u2,u3,u4}},{uj,{u1,u2,u3,u4}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

8. { {{1,0},{0,0}}, {{0,1},{0,0}}, {{0,0},{1,0}}, {{0,0},{0,1}} }

E11={{1,0},{0,0}};
E12={{0,1},{0,0}};
E21={{0,0},{1,0}};
E22={{0,0},{0,1}};
mats={E11,E12,E21,E22};
inner[A_,B_]:=Tr[Transpose[A].B]
Gram=Table[inner[mats[[i]],mats[[j]]],{i,Length[mats]},{j,Length[mats]}]//Simplify
NormsSq=Table[inner[mats[[i]],mats[[i]]],{i,Length[mats]}]//Simplify
isOrthogonal=And@@Flatten[Table[If[i==j,True,Gram[[i,j]]==0],{i,Length[mats]},{j,Length[mats]}]]
isOrthonormal=And@@Flatten[Table[Gram[[i,j]]==If[i==j,1,0],{i,Length[mats]},{j,Length[mats]}]]
{Gram,NormsSq,isOrthogonal,isOrthonormal}

9. {(1,2,-1,0,1), (2,-1,0,1,-2), (0,1,2,-1,0)}

u1={1,2,-1,0,1};
u2={2,-1,0,1,-2};
u3={0,1,2,-1,0};
Table[ui.uj,{ui,{u1,u2,u3}},{uj,{u1,u2,u3}}]//Simplify
Norms={Norm[u1],Norm[u2],Norm[u3]}//Simplify

10. { 1/Sqrt[2π], (cos x)/Sqrt[π], (sin x)/Sqrt[π], (cos 2x)/Sqrt[π], (sin 2x)/Sqrt[π] }

f1=1/Sqrt[2 Pi];
f2=Cos[x]/Sqrt[Pi];
f3=Sin[x]/Sqrt[Pi];
f4=Cos[2 x]/Sqrt[Pi];
f5=Sin[2 x]/Sqrt[Pi];
funcs={f1,f2,f3,f4,f5};
inner[p_,q_]:=Integrate[p*q,{x,-Pi,Pi}];
Gram=Table[inner[funcs[[i]],funcs[[j]]],{i,Length[funcs]},{j,Length[funcs]}]//Simplify
isOrthonormal=Simplify[Gram==IdentityMatrix[Length[funcs]]];
NormsSq=Diagonal[Gram];
CrossDots=Table[Gram[[i,j]],{i,Length[funcs]},{j,Length[funcs]}]//Simplify
{Gram,NormsSq,isOrthonormal}

Gram-Schmidt

1. {(1,2,1), (2,1,0), (1,0,1)}

v1={1,2,1};
v2={2,1,0};
v3={1,0,1};
MGS[{v1,v2,v3}]

2. {(1,1,0), (1,0,1)}

v1={1,1,0};
v2={1,0,1};
MGS[{v1,v2}]

3. {(1,1,1,1), (1,1,0,0), (1,0,0,0)}

v1={1,1,1,1};
v2={1,1,0,0};
v3={1,0,0,0};
MGS[{v1,v2,v3}]

4. {(2,0,1), (1,1,0), (0,1,1)}

v1={2,0,1};
v2={1,1,0};
v3={0,1,1};
MGS[{v1,v2,v3}]

5. {(1,0,1,0,1), (0,1,0,1,0), (1,1,0,0,0)}

v1={1,0,1,0,1};
v2={0,1,0,1,0};
v3={1,1,0,0,0};
MGS[{v1,v2,v3}]

6. {1, x, x^2}

Clear[x];
basis={1,x,x^2};
inner[p_,q_]:=Integrate[p*q,{x,0,1}];
u1=basis[[1]];
u2=Simplify[basis[[2]]-(inner[basis[[2]],u1]/inner[u1,u1]) u1];
u3=Simplify[basis[[3]]-(inner[basis[[3]],u1]/inner[u1,u1]) u1-(inner[basis[[3]],u2]/inner[u2,u2]) u2];
e1=Simplify[u1/Sqrt[inner[u1,u1]]];
e2=Simplify[u2/Sqrt[inner[u2,u2]]];
e3=Simplify[u3/Sqrt[inner[u3,u3]]];
{e1,e2,e3}

7.

v1={1,2,0,1};
v2={2,1,1,0};
v3={0,1,1,2};
MGS[{v1,v2,v3}]

8. A1 = {{1, 0}, {0, 1}}
    A2 = {{1, 1}, {0, 0}}
    A3 = {{0, 1}, {1, 0}}

Clear[A1,A2,A3];
A1={{1,0},{0,1}};
A2={{1,1},{0,0}};
A3={{0,1},{1,0}};
inner[A_,B_]:=Tr[Transpose[A].B];
u1=A1;
e1=u1/Sqrt[inner[u1,u1]]//Simplify;
u2=A2-(inner[A2,u1]/inner[u1,u1]) u1//Simplify;
e2=u2/Sqrt[inner[u2,u2]]//Simplify;
u3=A3
-inner[A3,e1] e1
-inner[A3,e2] e2//Simplify;
e3=u3/Sqrt[inner[u3,u3]]//Simplify;
{e1,e2,e3}

9. {{1,1,1,0,0}, {1,0,0,1,1}, {0,1,0,1,0}}

v1={1,1,1,0,0};
v2={1,0,0,1,1};
v3={0,1,0,1,0};
MGS[{v1,v2,v3}]

10. {1, Cos[x], Sin[x]}

f1[x_]:=1
f2[x_]:=Cos[x]
f3[x_]:=Sin[x]
funcs={f1,f2,f3};
inner[f_,g_]:=Integrate[f[x] g[x],{x,-Pi,Pi}]
GramSchmidtFunc[fs_List]:=Module[{u,i,j},u={fs[[1]]};
For[i=2,i<=Length[fs],i++,AppendTo[u,fs[[i]]-Sum[(inner[fs[[i]],u[[j]]]/inner[u[[j]],u[[j]]]) u[[j]],{j,1,i-1}]]];
u=Table[u[[k]]/Sqrt[inner[u[[k]],u[[k]]]],{k,Length[u]}];
u]
ortonormal=GramSchmidtFunc[funcs];
ortoEval[x_]:=ortonormal/. {f1->f1[x],f2->f2[x],f3->f3[x]}
ortoEval[x]