Skip to content

Functions as vectors

Treat a curve as a vector with a height at every point, measure angles between curves with an integral, and project e^x onto polynomials.

Helps to know first
This topic

First, the picture

A curve is a list of heights, one at every point. Watch the best constant, line, parabola and cubic close in on exe^x.

Projecting a curve

The best constant, line, parabola and cubic for e^x on −1 to 1.

The curve e^x from −1 to 1: a vector with a height at every x.

length of the gap
–
coefficients on P0, P1, …
–
0.00 / 14.00 s
Describe this picture

A plot of the curve exe^x from x=−1x=-1 to 11. Over about 13 s four fits appear in turn, each growing out of the one before and drawn over the curve with the gap between them shaded: the best constant, 1.1752; the best line, 1.1752+1.1036x1.1752+1.1036x; the best parabola, 0.9963+1.1036x+0.5367x20.9963+1.1036x+0.5367x^2; and the best cubic. The shaded gap shrinks at each step, and a readout gives its length, ∥f−p∥\lVert f-p\rVert: 0.930, 0.229, 0.038 and 0.0047. A second readout lists the coefficients on the Legendre building blocks P0P_0, P1P_1, P2P_2, P3P_3 used so far, (1.1752, 1.1036, 0.3578, 0.0705)(1.1752,\ 1.1036,\ 0.3578,\ 0.0705), which keep their earlier values as each new one joins. The step buttons move from fit to fit. There is no other control.

A curve is a long list

A vector in three dimensions is a list of three numbers. A sampled signal of 1000 samples is a list of 1000 numbers, a vector in 1000 dimensions. Now let the samples get closer and closer together. In the end there is a height at every point of an interval, and the list has become a curve.

Curves can be added and scaled like vectors: f+gf+g adds the heights at each point, and 2f2f doubles them. So a curve is a vector with a height at every point. The question is how to measure lengths and angles between them.

The inner product

For two lists, the dot product multiplies matching entries and adds them up. For two curves on an interval from aa to bb, multiply the heights at each point and add them up with an integral:

⟨f,g⟩=∫abf(x) g(x) dx.\langle f,g\rangle=\int_a^b f(x)\,g(x)\,\mathrm{d}x .

This is the inner product of the two functions. The angle brackets replace the dot. The length follows as before, ∥f∥2=⟨f,f⟩\lVert f\rVert^2=\langle f,f\rangle. On the interval from −1-1 to 11, the constant function 1 has ∥1∥2=∫−111 dx=2\lVert1\rVert^2=\int_{-1}^1 1\,\mathrm{d}x=2, so its length is 2\sqrt2.

Two functions are orthogonal when their inner product is zero. That does not mean their curves cross at a right angle. It means that where f gf\,g is positive and where it is negative, the areas cancel.

Two waves do not overlap

The inner product of two functions is the area under their product.

Two waves on −π to π: sin x and sin 2x.

signed area of the product
–
0.00 / 9.20 s
Describe this picture

Two panels, one above the other, on the interval from −π-\pi to π\pi. Above, the curves sin⁡x\sin x and sin⁡2x\sin 2x. Below, their product, drawn from left to right with the areas above the axis shaded in one colour and the areas below in another. A readout adds up the signed area, which comes to 0. Then the second curve slides over into sin⁡x\sin x itself, the product becomes sin⁡2x\sin^2x, all above the axis, and the readout gives its area, π=3.142\pi=3.142. The picture has no control.

So sin⁡x\sin x and sin⁡2x\sin 2x are orthogonal on [−π,π][-\pi,\pi], while ⟨sin⁡x,sin⁡x⟩=π\langle\sin x,\sin x\rangle=\pi. On [−1,1][-1,1], the functions 1 and xx are orthogonal: ∫−11x dx=0\int_{-1}^1x\,\mathrm{d}x=0, because the area left of 0 cancels the area right of it. The same reason makes sin⁡x\sin x and cos⁡x\cos x orthogonal on [−π,π][-\pi,\pi]: their product is odd.

Orthogonal polynomials

The powers 1,x,x2,x31,x,x^2,x^3 are not orthogonal on [−1,1][-1,1]: for example ⟨1,x2⟩=23\langle1,x^2\rangle=\tfrac23. Run Gram–Schmidt on them, with the integral as the dot product, and you get the Legendre polynomials:

P0(x)=1,P1(x)=x,P2(x)=12(3x2−1),P3(x)=12(5x3−3x),\begin{aligned} P_0(x)&=1, & P_1(x)&=x,\\ P_2(x)&=\tfrac12(3x^2-1), & P_3(x)&=\tfrac12(5x^3-3x), \end{aligned}

with ⟨Pk,Pk⟩=22k+1\langle P_k,P_k\rangle=\dfrac{2}{2k+1}. They are written with an argument, Pk(x)P_k(x), so they are not confused with a projection matrix. This page keeps their usual scale, which is not length 1.

Projecting a curve

The best fit to ff by a combination of orthogonal functions uku_k is the projection of Projections, with integrals in place of dot products:

p=∑k⟨f,uk⟩⟨uk,uk⟩ uk.p=\sum_k\frac{\langle f,u_k\rangle}{\langle u_k,u_k\rangle}\,u_k .

“Best” means that ∥f−p∥\lVert f-p\rVert, the length of the gap, is as small as any combination can make it. Each coefficient is a separate shadow, so adding a new uku_k never changes the earlier coefficients. That is the second readout in the picture at the top of the page.

Here is f(x)=exf(x)=e^x on [−1,1][-1,1]:

  • On P0P_0: ⟨ex,1⟩=e−e−1=2.3504\langle e^x,1\rangle=e-e^{-1}=2.3504, divided by 2: 1.17521.1752. The best constant is the average height of the curve.
  • On P1P_1: ⟨ex,x⟩=2/e=0.7358\langle e^x,x\rangle=2/e=0.7358, divided by 23\tfrac23: 1.10361.1036.
  • On P2P_2: ⟨ex,P2⟩=e−7/e=0.14313\langle e^x,P_2\rangle=e-7/e=0.14313, divided by 25\tfrac25: 0.35780.3578.
  • On P3P_3: the coefficient is 0.07050.0705.

Written in powers of xx, the best parabola is 0.9963+1.1036x+0.5367x20.9963+1.1036x+0.5367x^2. The coefficients in powers of xx do change from fit to fit, because the powers are not orthogonal; only the coefficients on the PkP_k stay fixed.

The gap shrinks fast. Its squared length is 1−e−2=0.86471-e^{-2}=0.8647 after the constant, 1−7e−2=0.052651-7e^{-2}=0.05265 after the line, and 0.001440.00144 after the parabola. Each step removes the square of the new shadow’s length, the right-angle rule again. The lengths in the readout are the square roots: 0.930, 0.229, 0.038, and 0.0047 after the cubic.

Compare a Taylor parabola, 1+x+x2/21+x+x^2/2, which copies exe^x perfectly near x=0x=0. At x=1x=1 it gives 2.52.5, while the projection gives 2.6372.637 and the truth is 2.7182.718. Over the whole interval, the largest miss of the Taylor parabola is 0.2180.218, and of the projection only 0.0820.082. Taylor is best at one point; the projection is best across the interval.

Worked example

  1. Orthogonal. On [−1,1][-1,1], ⟨1,x⟩=0\langle1,x\rangle=0, and ∥1∥=2\lVert1\rVert=\sqrt2.
  2. Sines. On [−π,π][-\pi,\pi], ⟨sin⁡x,sin⁡2x⟩=0\langle\sin x,\sin2x\rangle=0 and ⟨sin⁡x,sin⁡x⟩=π\langle\sin x,\sin x\rangle=\pi; sin⁡x\sin x and cos⁡x\cos x are orthogonal, odd times even.
  3. The best constant. For exe^x on [−1,1][-1,1], the best constant is its average, 1.17521.1752.
  4. The best parabola. 0.9963+1.1036x+0.5367x20.9963+1.1036x+0.5367x^2, with a gap of length 0.0380.038.
  5. A straight line by sines. Project f(x)=xf(x)=x on [−π,π][-\pi,\pi] onto sin⁡x\sin x, sin⁡2x\sin2x, sin⁡3x\sin3x. Each coefficient is ⟨x,sin⁡kx⟩/π=2(−1)k+1/k\langle x,\sin kx\rangle/\pi=2(-1)^{k+1}/k: 22, −1-1 and 23\tfrac23. The squared length of xx is 2π3/3=20.6712\pi^3/3=20.671. After one, two and three sines, the squared gap is 8.1048.104, 4.9634.963 and 3.5673.567: each sine removes π\pi times its coefficient squared.

Where you’ll meet this

A maths library computes sin⁡x\sin x or exe^x by first moving xx into a short interval, then evaluating a polynomial chosen to be close to best there. A Fourier series is a projection onto sines and cosines, and keeping more of them shrinks the gap, as item 5 does for a straight line.

In signal processing · projections onto harmonics

Convergence and the Gibbs phenomenon shows a Fourier series as a projection onto the harmonics: the closest fit in this page’s sense, with an overshoot at every jump. Analog prototype filters builds its Chebyshev filters on Chebyshev polynomials, another family of orthogonal polynomials.

Reference card

QuantityFormulaNotes
Inner product⟨f,g⟩=∫abf(x)g(x) dx\langle f,g\rangle=\int_a^bf(x)g(x)\,\mathrm{d}xthe dot product for curves
Length∥f∥2=⟨f,f⟩\lVert f\rVert^2=\langle f,f\rangle
Orthogonal⟨f,g⟩=0\langle f,g\rangle=0areas of f gf\,g cancel
Legendre1, x, 12(3x2−1), 12(5x3−3x)1,\ x,\ \tfrac12(3x^2-1),\ \tfrac12(5x^3-3x)orthogonal on [−1,1][-1,1]; ⟨Pk,Pk⟩=22k+1\langle P_k,P_k\rangle=\tfrac2{2k+1}
Projectionp=∑k⟨f,uk⟩⟨uk,uk⟩ukp=\sum_k\dfrac{\langle f,u_k\rangle}{\langle u_k,u_k\rangle}u_korthogonal uku_k
Gap∥f−p∥2=∥f∥2−∑k⟨f,uk⟩2⟨uk,uk⟩\lVert f-p\rVert^2=\lVert f\rVert^2-\sum_k\dfrac{\langle f,u_k\rangle^2}{\langle u_k,u_k\rangle}shrinks as terms are added
exe^x on [−1,1][-1,1]gaps 0.930, 0.229, 0.038, 0.0047constant, line, parabola, cubic

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look