Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- v = Function[x, Evaluate[x^#]] & /@ Range[0, 5];
- u = v;
- For[i = 2, i < 7, i++,
- u[[i]] = Function[x,
- v[[i]][x] -
- Sum[Integrate[v[[i]][x]*u[[j]][x], {x, -Pi, Pi}]/
- Integrate[u[[j]][x]^2, {x, -Pi, Pi}]*u[[j]][x], {j, 1, i - 1}]
- ]
- ]
- Orthogonalize[x^Range[5], Integrate[#1*#2, {x, -[Pi], [Pi]}] &]
- inn = Integrate[#1*#2, {x, -[Pi], [Pi]}] &;
- v = x^Range[5];
- u = ConstantArray[0, Length@v];
- u[[1]] = v[[1]];
- Do[
- u[[i]] = v[[i]] - Total@Table[
- u[[j]]*inn[v[[i]], u[[j]]]/inn[u[[j]], u[[j]]],
- {j, 1, i - 1}],
- {i, 2, Length@v}
- ]
- u
- (*{x, x^2, -((3 [Pi]^2 x)/5) + x^3, -(5/7) [Pi]^2 x^2 +
- x^4, -((3 [Pi]^4 x)/7) + x^5 -
- 10/9 [Pi]^2 (-((3 [Pi]^2 x)/5) + x^3)}*)
- Outer[inn, u, u] // MatrixForm
- oneStepOrtogonalizeGen[vec_, {}, _, _, _] := vec;
- oneStepOrtogonalizeGen[vec_, vecmat_List, dotF_, plusF_, timesF_] :=
- Fold[plusF[#1, timesF[-dotF[vec, #2]/dotF[#2, #2], #2]] &, vec, vecmat];
- GSOrthogonalizeGen[startvecs_List, dotF_, plusF_, timesF_] :=
- Fold[Append[#1,oneStepOrtogonalizeGen[#2, #1, dotF, plusF, timesF]] &, {}, startvecs];
- normalizeGen[vec_, dotF_, timesF_] := timesF[1/Sqrt[dotF[vec, vec]], vec];
- GSOrthoNormalizeGen[startvecs_List, dotF_, plusF_, timesF_] :=
- Map[normalizeGen[#, dotF, timesF] &, GSOrthogonalizeGen[startvecs, dotF, plusF, timesF]];
- hermiteDot[f_Function, g_Function] :=
- Module[{x}, Integrate[f[x]*g[x]*Exp[-x^2], {x, -Infinity, Infinity}]];
- SetAttributes[functionPlus, {Flat, Orderless, OneIdentity}];
- functionPlus[f__Function] := With[{expr = Plus @@ Through[{f}[#]]}, expr &];
- SetAttributes[functionTimes, {Flat, Orderless, OneIdentity}];
- functionTimes[a___, f_Function] /; FreeQ[{a}, # | Function] :=
- With[{expr = Times[a, f[#]]}, expr &];
- In[114]:= hermiteDot[#^2 &, #^4 &]
- Out[114]= (15 Sqrt[[Pi]])/8
- In[107]:= functionPlus[# &, #^2 &, Sin[#] &]
- Out[107]= Sin[#1] + #1 + #1^2 &
- In[111]:= functionTimes[z, #^2 &, x, 5]
- Out[111]= 5 x z #1^2 &
- In[115]:=
- results =
- GSOrthoNormalizeGen[{1 &, # &, #^2 &, #^3 &, #^4 &}, hermiteDot,
- functionPlus, functionTimes]
- Out[115]= {1/[Pi]^(1/4) &, (Sqrt[2] #1)/[Pi]^(1/4) &, (
- Sqrt[2] (-(1/2) + #1^2))/[Pi]^(1/4) &, (2 (-((3 #1)/2) + #1^3))/(
- Sqrt[3] [Pi]^(1/4)) &, (Sqrt[2/3] (-(3/4) + #1^4 -
- 3 (-(1/2) + #1^2)))/[Pi]^(1/4) &}
- In[116]:= Through[results[x]]
- Out[116]= {1/[Pi]^(1/4),(Sqrt[2] x)/[Pi]^(1/4),(Sqrt[2] (-(1/2)+x^2))/[Pi]^(1/4),
- (2 (-((3 x)/2)+x^3))/(Sqrt[3] [Pi]^(1/4)),(Sqrt[2/3] (-(3/4)+x^4-3 (-(1/2)+x^2)))/[Pi]^(1/4)}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement