4.5.2Linear Algebra (Full)

Dot product — formula, cosine formula, Cauchy-Schwarz inequality proof

1,648 words7 min readdifficulty · medium6 backlinks

1. The algebraic definition

WHAT is this really? Multiply matching components, add them up.

WHY this and not something else? Because it gives us the length for free. Set b=a\mathbf{b}=\mathbf{a}: aa=a12+a22++an2=a2\mathbf{a}\cdot\mathbf{a} = a_1^2 + a_2^2 + \cdots + a_n^2 = \|\mathbf{a}\|^2 This is just the Pythagorean theorem! So the dot product contains the notion of distance. That is the design goal it was built to satisfy.

Basic properties (all provable from the sum)

  • Commutative: ab=ba\mathbf{a}\cdot\mathbf{b}=\mathbf{b}\cdot\mathbf{a} (since aibi=biaia_ib_i=b_ia_i).
  • Distributive: a(b+c)=ab+ac\mathbf{a}\cdot(\mathbf{b}+\mathbf{c})=\mathbf{a}\cdot\mathbf{b}+\mathbf{a}\cdot\mathbf{c}.
  • Scalar pull-out: (λa)b=λ(ab)(\lambda\mathbf{a})\cdot\mathbf{b}=\lambda(\mathbf{a}\cdot\mathbf{b}).
  • Positive: aa0\mathbf{a}\cdot\mathbf{a}\ge 0, and =0=0 only if a=0\mathbf{a}=\mathbf{0}.

2. The cosine (geometric) formula — derived, not memorized

HOW do we get this? Use the Law of Cosines on the triangle formed by a\mathbf{a}, b\mathbf{b} and the side ab\mathbf{a}-\mathbf{b}.

Law of cosines on that triangle: ab2=a2+b22abcosθ\|\mathbf{a}-\mathbf{b}\|^2 = \|\mathbf{a}\|^2 + \|\mathbf{b}\|^2 - 2\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta Why this step? The vector ab\mathbf{a}-\mathbf{b} is the side opposite to angle θ\theta.

Now expand the left side algebraically using the dot product: ab2=(ab)(ab)=aa2ab+bb\|\mathbf{a}-\mathbf{b}\|^2 = (\mathbf{a}-\mathbf{b})\cdot(\mathbf{a}-\mathbf{b}) = \mathbf{a}\cdot\mathbf{a} - 2\,\mathbf{a}\cdot\mathbf{b} + \mathbf{b}\cdot\mathbf{b} =a22ab+b2= \|\mathbf{a}\|^2 - 2\,\mathbf{a}\cdot\mathbf{b} + \|\mathbf{b}\|^2 Why this step? We use distributivity and aa=a2\mathbf{a}\cdot\mathbf{a}=\|\mathbf{a}\|^2.

Set the two expressions for ab2\|\mathbf{a}-\mathbf{b}\|^2 equal. The a2\|\mathbf{a}\|^2 and b2\|\mathbf{b}\|^2 cancel: 2ab=2abcosθab=abcosθ-2\,\mathbf{a}\cdot\mathbf{b} = -2\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta \quad\Longrightarrow\quad \boxed{\mathbf{a}\cdot\mathbf{b}=\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta}

Angle extraction: cosθ=abab,ab    ab=0\cos\theta = \frac{\mathbf{a}\cdot\mathbf{b}}{\|\mathbf{a}\|\,\|\mathbf{b}\|}, \qquad \mathbf{a}\perp\mathbf{b}\iff \mathbf{a}\cdot\mathbf{b}=0

Figure — Dot product — formula, cosine formula, Cauchy-Schwarz inequality proof

3. Cauchy–Schwarz inequality

WHY is it "obviously" true geometrically? Because ab=abcosθ\mathbf{a}\cdot\mathbf{b}=\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta and cosθ1|\cos\theta|\le 1. Done!

But that geometric "proof" secretly assumes we already have an angle θ\theta — which is fine in R2,R3\mathbb{R}^2,\mathbb{R}^3 but not obvious in abstract spaces. So we prove it purely algebraically, which then justifies defining the angle.

Derivation from scratch (the discriminant trick)

Consider the real function for any real tt: f(t)=atb20f(t) = \|\mathbf{a} - t\mathbf{b}\|^2 \ge 0 Why start here? A squared length is never negative — that single fact is the whole engine.

Expand it: f(t)=(atb)(atb)=a22t(ab)+t2b2f(t) = (\mathbf{a}-t\mathbf{b})\cdot(\mathbf{a}-t\mathbf{b}) = \|\mathbf{a}\|^2 - 2t\,(\mathbf{a}\cdot\mathbf{b}) + t^2\|\mathbf{b}\|^2

This is a quadratic in tt of the form At2+Bt+CAt^2+Bt+C with A=b2,B=2(ab),C=a2.A=\|\mathbf{b}\|^2,\quad B=-2(\mathbf{a}\cdot\mathbf{b}),\quad C=\|\mathbf{a}\|^2.

Since f(t)0f(t)\ge 0 for all tt, the parabola never crosses below the axis, so its discriminant must satisfy B24AC0B^2-4AC\le 0: 4(ab)24b2a204(\mathbf{a}\cdot\mathbf{b})^2 - 4\|\mathbf{b}\|^2\|\mathbf{a}\|^2 \le 0 Why this step? A non-negative upward parabola has at most one real root → discriminant 0\le 0.

Divide by 4 and rearrange: (ab)2a2b2(\mathbf{a}\cdot\mathbf{b})^2 \le \|\mathbf{a}\|^2\|\mathbf{b}\|^2 Take square roots (both sides 0\ge0): abab|\mathbf{a}\cdot\mathbf{b}| \le \|\mathbf{a}\|\,\|\mathbf{b}\| \qquad\blacksquare

Equality case: B24AC=0B^2-4AC=0 means f(t)=0f(t)=0 for some t=t0t=t_0, i.e. at0b=0a=t0b\|\mathbf{a}-t_0\mathbf{b}\|=0\Rightarrow \mathbf{a}=t_0\mathbf{b}. So equality     \iff vectors are parallel. ✔


4. Worked examples


5. Common mistakes (steel-manned)


6. Flashcards

Dot product component formula
ab=iaibi\mathbf{a}\cdot\mathbf{b}=\sum_i a_ib_i
Dot product geometric formula
ab=abcosθ\mathbf{a}\cdot\mathbf{b}=\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta
Length from dot product
a=aa\|\mathbf{a}\|=\sqrt{\mathbf{a}\cdot\mathbf{a}}
Condition for perpendicular vectors
ab=0\mathbf{a}\cdot\mathbf{b}=0
Cauchy–Schwarz inequality
abab|\mathbf{a}\cdot\mathbf{b}|\le\|\mathbf{a}\|\|\mathbf{b}\|
When is Cauchy–Schwarz an equality?
When a,b\mathbf{a},\mathbf{b} are parallel (one is a scalar multiple of the other)
Key idea behind the C–S proof
f(t)=atb20f(t)=\|\mathbf{a}-t\mathbf{b}\|^2\ge0 → quadratic with discriminant 0\le0
Tool used to derive the cosine formula
Law of cosines on the triangle with sides a,b,ab\mathbf a,\mathbf b,\mathbf a-\mathbf b
Is the dot product a scalar or vector?
A scalar (single number)
cosθ\cos\theta in terms of dot product
cosθ=abab\cos\theta=\dfrac{\mathbf{a}\cdot\mathbf{b}}{\|\mathbf{a}\|\|\mathbf{b}\|}

Recall Feynman: explain to a 12-year-old

Imagine two arrows starting from the same spot. The dot product is a "teamwork score." If both arrows point the same way, they're a great team → big positive score. If one points left while the other points right, they fight → negative score. If they're at a perfect right angle, they ignore each other → score is exactly zero. To get the score you just multiply matching parts and add them up. And there's a rule (Cauchy–Schwarz) that says the teamwork score can never beat the product of the two arrows' lengths — you can't get more out than the arrows actually have.

Concept Map

set b=a

output

provable

is

applied to triangle

expand a-b squared

distributivity used in

yields

theta=90 gives zero

bounds cos in -1,1

same object two faces

Algebraic def sum ai bi

Length norm a

Scalar not vector

Commutative distributive scalar pull-out positive

Pythagorean theorem

Law of cosines

Derivation

Cosine formula a.b = norm cos theta

Perpendicular test

Cauchy-Schwarz inequality

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, dot product ek simple machine hai: do vectors leta hai aur ek single number (scalar) deta hai. Formula hai matching components multiply karke add kar do: ab=a1b1+a2b2+\mathbf{a}\cdot\mathbf{b}=a_1b_1+a_2b_2+\dots. Ye number batata hai ki do vectors kitna same direction mein point kar rahe hain. Same direction → bada positive, perpendicular (90°) → exactly zero, opposite → negative. Isliye "perpendicular check" sirf dekho dot product zero hai ya nahi.

Cosine formula ab=abcosθ\mathbf{a}\cdot\mathbf{b}=\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta ko ratna mat — derive karo Law of Cosines se. Triangle banao jiski sides a\mathbf{a}, b\mathbf{b} aur ab\mathbf{a}-\mathbf{b} ho. ab2\|\mathbf{a}-\mathbf{b}\|^2 ko do tarah se likho — ek law of cosines se, ek algebra se — equal karo, sab cancel ho jaata hai aur formula nikal aata hai. Yahi do "faces" hain ek hi cheez ke: ek calculation ke liye, ek samajhne ke liye.

Cauchy–Schwarz kehta hai abab|\mathbf{a}\cdot\mathbf{b}|\le\|\mathbf{a}\|\|\mathbf{b}\| — yaani teamwork score kabhi bhi dono arrows ki lengths ke product se zyada nahi ho sakta. "Shadow stick se lambi nahi hoti." Proof ka jugaad: function f(t)=atb2f(t)=\|\mathbf{a}-t\mathbf{b}\|^2 lo. Ye length ka square hai, toh kabhi negative nahi ho sakta. Ye tt mein quadratic hai, aur agar parabola kabhi neeche nahi jaati toh uska discriminant 0\le 0 hona chahiye. Wahi condition rearrange karo aur Cauchy–Schwarz aa jaata hai. Equality tabhi jab vectors parallel ho. Bas itna hi — pura geometry sirf is ek "length square negative nahi hota" se nikal aata hai.

Go deeper — visual, from zero

Test yourself — Linear Algebra (Full)

Connections