3
$\begingroup$

A family of functions is known as $\left(\varphi_{0}, \varphi_{1}, \cdots, \varphi_{n}\right)$.

I'd like to know how to express their inner product conveniently as follows:

$$\left(\begin{array}{cccc} \left(\varphi_{0}, \varphi_{0}\right) & \left(\varphi_{0}, \varphi_{1}\right) & \cdots & \left(\varphi_{0}, \varphi_{n}\right) \\ \left(\varphi_{1}, \varphi_{0}\right) & \left(\varphi_{1}, \varphi_{1}\right) & \cdots & \left(\varphi_{1}, \varphi_{n}\right) \\ \vdots & \vdots & & \vdots \\ \left(\varphi_{n}, \varphi_{0}\right) & \left(\varphi_{n}, \varphi_{1}\right) & \cdots & \left(\varphi_{n}, \varphi_{n}\right) \end{array}\right)$$

Where $(f(x), g(x))$ is the inner product: $(f(x), g(x))=\int_{a}^{b} f(x) g(x) \mathrm{d} x$

We can take $\{1,x,x^2,x^3,x^4\}$ and $\{a=-1,b=1\}$ as an example to realize the above requirements.

Outer[Integrate[#1*#2, {x, -1, 1}] &, {1, x, x^2, x^3}, {1, x, x^2, x^3}]

I wonder if there are any other ways to achieve this?

$\endgroup$
1
  • 4
    $\begingroup$ Just use Outer? Or am I missing something? With[{fns = Array[\[Phi], 3, 0]}, Outer[Integrate[#1[x]*#2[x], {x, a, b}] &, fns, fns]] - in your concrete case With[{fns = Array[Power[x, #] &, 5, 0]}, Outer[Integrate[#1*#2, {x, -1, 1}] &, fns, fns]] giving result {{2, 0, 2/3, 0, 2/5}, {0, 2/3, 0, 2/5, 0}, {2/3, 0, 2/5, 0, 2/7}, {0, 2/5, 0, 2/7, 0}, {2/5, 0, 2/7, 0, 2/9}} $\endgroup$ – flinty Sep 15 '20 at 1:03
7
$\begingroup$

Since you're dealing with inner products, you can take advantage of the symmetry that $\left<f(x), g(x)\right> = \left<g(x), f(x)\right>$ to only compute the $n(n+1)/2$ upper triangular elements instead of the total $n^2$.

So we can use SymmetrizedArray as

ipmatrix[ϕ_, n_, {a_, b_} /; a <= b] := SymmetrizedArray[
  {j_, k_} :> Integrate[ϕ[x, j]*ϕ[x, k], {x, a, b}],
  {n, n},
  Symmetric
]

To yield your example of

Normal@ipmatrix[#1^(#2 - 1) &, 5, {-1, 1}]

{{2, 0, 2/3, 0, 2/5}, {0, 2/3, 0, 2/5, 0}, {2/3, 0, 2/5, 0, 2/7}, {0, 2/5, 0, 2/7, 0}, {2/5, 0, 2/7, 0, 2/9}}

$\endgroup$
-1
$\begingroup$

The results of the two methods are the same $\color{Gray} {\text{(2001 武汉 岩石 数值分析 4)}} $:

ClearAll["Global`*"]
f[x_] := x^3
L[a_, b_, c_] := Integrate[(f[x] - (a*x^2 + b*x + c))^2, {x, 0, 1}]
StagnationPoints = 
 Solve[{D[L[a, b, c], a] == 0, D[L[a, b, c], b] == 0, 
       D[L[a, b, c], c] == 0}]
Print[Style["The best quadratic approximation polynomial is:", Red, Bold], 
   a*x^2 + b*x + c /. Flatten[StagnationPoints]]

LinearSolve[
  Outer[Integrate[#1*#2, {x, 0, 1}] &, {1, x, x^2}, {1, x, x^2}], 
  Map[Integrate[#1*x^3, {x, 0, 1}] &, {1, x, x^2}]].{1, x, x^2}
$\endgroup$
1
  • 1
    $\begingroup$ (-1) This isn't an answer to your question at all, why do you post it here? $\endgroup$ – xzczd Sep 15 '20 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.