1.2.7Calculus & Optimization Basics

Taylor series approximation

1,602 words7 min readdifficulty · medium1 backlinks

WHAT is a Taylor series?


HOW do we derive it? (from scratch)

We want a polynomial P(x)=c0+c1(xa)+c2(xa)2+P(x)=c_0 + c_1(x-a) + c_2(x-a)^2 + \dots that agrees with ff as closely as possible at x=ax=a.

Step 1 — Match the value. Set x=ax=a: every term with (xa)(x-a) vanishes, so P(a)=c0P(a)=c_0. We want P(a)=f(a)P(a)=f(a), so c0=f(a)c_0=f(a). Why this step? The constant term controls the height at aa; nothing else touches it.

Step 2 — Match the slope. Differentiate: P(x)=c1+2c2(xa)+3c3(xa)2+P'(x)=c_1 + 2c_2(x-a) + 3c_3(x-a)^2+\dots. Set x=ax=a: P(a)=c1P'(a)=c_1. We want P(a)=f(a)P'(a)=f'(a), so c1=f(a)c_1=f'(a). Why this step? Matching slope makes the line touch ff tangentially, not just cross it.

Step 3 — Match the curvature. Differentiate again: P(x)=2c2+6c3(xa)+P''(x)=2c_2 + 6c_3(x-a)+\dots. Set x=ax=a: P(a)=2c2P''(a)=2c_2, so c2=f(a)2c_2=\dfrac{f''(a)}{2}. Why this step? The factor 22 appears because (xa)2(x-a)^2 differentiated twice gives 22. This is the seed of the factorial.

Step 4 — See the pattern. Differentiate nn times: the term cn(xa)nc_n(x-a)^n becomes n!cnn!\,c_n at x=ax=a (all lower terms die, all higher terms still have (xa)(x-a)). So f(n)(a)=n!cn    cn=f(n)(a)n!.f^{(n)}(a)=n!\,c_n \;\Rightarrow\; c_n=\frac{f^{(n)}(a)}{n!}. Why this step? The n!n! is not magic — it's exactly the number that xnx^n spits out when differentiated nn times. Dividing by it "undoes" that factor.

Plugging back gives the definition. We derived it by simply demanding all derivatives match.


Figure — Taylor series approximation

Worked examples


Common mistakes


Flashcards

What does the nn-th Taylor coefficient equal?
f(n)(a)n!\dfrac{f^{(n)}(a)}{n!} — the nn-th derivative at aa divided by n!n!.
Why is there a factorial in the denominator?
Differentiating (xa)n(x-a)^n exactly nn times yields n!n!; dividing by it cancels that factor so derivatives match.
What is a Maclaurin series?
A Taylor series expanded around a=0a=0.
Give the Maclaurin series of exe^x.
1+x+x22!+x33!+1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\dots
How does the truncation error scale near aa?
Like (xa)k+1(x-a)^{k+1} for an order-kk polynomial (Lagrange remainder).
Which Taylor order corresponds to gradient descent?
First order: L(θ0+Δ)L(θ0)+LΔL(\theta_0+\Delta)\approx L(\theta_0)+\nabla L^\top\Delta.
Which order corresponds to Newton's method?
Second order, giving step Δ=H1L\Delta=-H^{-1}\nabla L.
Does a Taylor series always equal its function?
No — only within its radius of convergence, and some smooth functions (e.g. e1/x2e^{-1/x^2}) aren't equal to their series at all.
Multivariable 2nd-order Taylor form?
f(x0+Δ)f(x0)+fΔ+12ΔHΔf(x_0+\Delta)\approx f(x_0)+\nabla f^\top\Delta+\tfrac12\Delta^\top H\Delta.

Recall Explain to a 12-year-old (Feynman)

Imagine you know exactly where a toy car is, how fast it's going, and how fast it's speeding up — all at one moment. From just those three facts you can guess pretty well where it'll be a split-second later. Taylor series does this for any curve: it uses the height, slope, bend, twist... at one spot to draw a copy of the curve nearby. The more facts (derivatives) you use, the better the copy — but only for spots close to where you started. Far away, your guess falls apart.

Connections

  • Derivatives and gradients — Taylor is built entirely from derivatives.
  • Gradient Descent — the 1st-order Taylor truncation.
  • Newton's Method — the 2nd-order Taylor truncation.
  • Hessian matrix — the curvature term of multivariable Taylor.
  • Convex functions — 2nd-order Taylor with H0H\succeq 0 implies convexity.
  • Approximation error and Big-O — remainder term formalizes accuracy.

Concept Map

match value slope curvature

coefficients cn = f^n a / n!

infinite terms

when a=0

truncation leaves

shrinks like x-a ^ k+1

1st-order fit

2nd-order fit parabola

undoes differentiation factor

all f^n 0 = 1

Function f smooth at a

Taylor polynomial Pk

Derivatives f^n at a

Taylor series

Maclaurin series

Remainder Rk

Local accuracy near a

Gradient descent

Newton's method

factorial n!

e^x example

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Taylor series ka core idea simple hai: koi bhi complicated function agar tum ek point ke paas dekho, to woh ek polynomial jaisa behave karta hai. Us point par function ki height (value), slope (pehla derivative), curvature (doosra derivative) — bas yeh saari cheezein match kar lo, aur tumne function ki ek local copy bana li. Jitne zyada derivatives match karoge (higher order), utni achhi copy — lekin sirf us point ke nazdeek. Door jaake sab galat ho jaata hai.

Factorial kyun aata hai? Kyunki jab tum (xa)n(x-a)^n ko nn baar differentiate karte ho to n!n! nikalta hai. Us n!n! ko cancel karne ke liye hi hum divide karte hai. Agar factorial bhool gaye, to exe^x ka series x=1x=1 par infinity ban jaata — bilkul bekaar. Isliye yaad rakho: "divide by n-factorial or terms go feral".

ML mein yeh direct kaam aata hai. Loss function L(θ)L(\theta) ka first-order Taylor lo — value plus gradient·step — aur usse tumhe gradient descent milta hai (niche ki taraf chalo). Second-order lo — gradient plus Hessian curvature — aur usse Newton's method milta hai, jahan tum ek parabola fit karke seedha uske bottom par jump karte ho. Matlab jo optimizers tum roz use karte ho, woh actually truncated Taylor series hi hai.

Ek warning: Taylor series hamesha function ke barabar nahi hoti. 11x\frac{1}{1-x} ka series sirf x<1|x|<1 mein chalta hai. Aur point sahi choose karna — lnx\ln x ko x=1x=1 ke paas expand karo, x=0x=0 par nahi (wahan defined hi nahi hai). Yaad rakho: Taylor local hai, global nahi.

Go deeper — visual, from zero

Test yourself — Calculus & Optimization Basics

Connections