Physics Library / FS02

Inner Product Lab

Vectors in the plane

Inner product ⟨u, v⟩
Norms ‖u‖ / ‖v‖
Inner-product angle θ

Objects and projection

uvc vr = u − c v

Signed contributions

Sum

Find the component along v

c* = ⟨u, v⟩ / ⟨v, v⟩   ·   r = u − c v

Optimal coefficient c*
Residual test ⟨r, v⟩
Squared error ‖r‖²

Geometry inside the span of u and v

This diagram uses coordinates defined by the chosen inner product. In function and matrix modes its axes are abstract directions, not x on the function graph or matrix row numbers. A mirror image would express the same geometry.

Error as the coefficient changes

Multiply matching components, then add

ComponentuvMeasureContribution

One geometry, different kinds of objects

A vector is not necessarily an arrow in space

The arrow picture is one representation of a vector. What matters more generally is that objects can be added and multiplied by scalars. A pair of coordinates, an entire function and a matrix can all obey these rules. An inner product equips the chosen space with notions of length, angle and orthogonality.

The vector mode uses the Euclidean dot product, u₁v₁ + u₂v₂. Matching components may contribute positively or negatively. Their sum is one scalar, not another vector. The sign of that scalar distinguishes acute and obtuse angles when both objects are nonzero.

How a list becomes a function inner product

Sample two functions at the same positions, multiply matching values and add. To approximate an integral you must also include each sample's interval width Δx: Σ w(xᵢ)u(xᵢ)v(xᵢ)Δx. Increasing N makes the midpoint rectangles thinner. An unweighted raw dot product of samples, without Δx, generally grows with sample density rather than approaching the intended integral.

Function mode uses real polynomials of degree at most three and computes their inner products by integrating the polynomial product analytically. The midpoint sum is displayed separately as an approximation. The integral returns one scalar from two whole functions; the shaded product curve is its integrand, not the inner product's output.

Cancellation, interval and weight are part of the geometry

The functions 1 and x are orthogonal on [−1, 1] because their product has equal positive and negative signed areas. They need not look perpendicular, and their graphs need not meet at right angles. On [0, 1] the same inner product is 1/2, so changing the interval changes the geometry.

A positive weight changes which parts of the interval count more strongly. The ramp is w(x) = 2(x − a)/(b − a); on [0, 1] it is the article's 2x. It vanishes only at the left endpoint and is positive in the interior, so it still defines a genuine inner product on these polynomials. The 1 + x² weight emphasizes both ends of a symmetric interval.

Projection is the same calculation in every mode

To approximate u by a multiple c v, choose c so that r = u − c v has no component along v. Solving ⟨r, v⟩ = 0 gives c* = ⟨u, v⟩/‖v‖² when v is nonzero. That same coefficient minimizes E(c) = ‖u − c v‖². Turn off “Use optimal c” to move away from the minimum and watch the residual gain a component along v.

At the optimum, ‖u‖² = ‖c*v‖² + ‖r‖² is Pythagoras in the chosen inner-product geometry. Away from the optimum an extra cross term 2c⟨r, v⟩ is generally needed. Normalizing v makes ‖v‖ = 1 and simplifies the coefficient, but does not change the projected object in its one-dimensional span.

Matrices: an abstract example without spatial arrows

The four entries of a real 2×2 matrix form a four-dimensional vector space. The Frobenius inner product is ⟨A, B⟩ = tr(AᵀB) = Σ AᵢⱼBᵢⱼ. It is not ordinary matrix multiplication and not the determinant. The matrix tiles show the objects themselves; the abstract geometry diagram shows their relation under this inner product.

Projecting A onto the identity I gives c* = tr(A)/2. Subtracting c*I leaves a trace-free matrix. In the other preset a symmetric matrix is orthogonal to a skew-symmetric matrix because the paired off-diagonal contributions cancel. There is no literal physical angle between the two grids of numbers, yet their inner-product angle is well defined.

The article's examples and the important edge cases

On [−1, 1], the norm of x is √(2/3). Projecting x² onto 1 gives the constant 1/3, and projecting x³ onto x gives (3/5)x. On [0, 1], projecting x onto 1 with weight 2x gives 2/3 instead of the unweighted average 1/2. These are included as presets; edit their coefficients, interval or weight to explore what changes.

The zero object has zero norm and cannot be normalized. If either object is zero, their angle is undefined. If the target v is zero, the projection object is still zero, but no unique coefficient can be recovered by division; every c gives the same error. All examples here are real and dimensionless. Complex spaces require conjugation, and physical function inner products may carry units from both functions, the measure and the weight.

Function mode explores a four-dimensional polynomial subspace, not all square-integrable functions. For general L² spaces, functions equal almost everywhere represent the same element; continuity makes zero norm equivalent to the zero polynomial here. Multiple-basis Fourier coefficient extraction is a natural follow-on, not an extra assumption of this one-direction projection lab.