Lesson 11 of 18

Maclaurin Series for eˣ

Maclaurin Series for exe^x

The most important Taylor series is for exe^x centered at a=0a = 0 (Maclaurin):

e^x = sum_{k=0}^{infty} rac{x^k}{k!} = 1 + x + rac{x^2}{2!} + rac{x^3}{3!} + rac{x^4}{4!} + cdots

Why This Works

Every derivative of exe^x is exe^x, so f(k)(0)=e0=1f^{(k)}(0) = e^0 = 1 for all kk. The Taylor series becomes:

P_n(x) = sum_{k=0}^n rac{x^k}{k!}

Convergence

This series converges for all xx. By the ratio test:

ight| = rac{|x|}{k+1} o 0 quad ext{as } k o infty$$ ### How Fast It Converges For $x=1$ (computing $e$): | $n$ | $P_n(1)$ | Error | |-----|----------|-------| | $5$ | $2.7167$ | $0.0016$ | | $10$ | $2.71828$ | $< 10^{-7}$ | | $20$ | $2.71828182ldots$ | machine precision | ### Efficient Evaluation (Horner's Method Alternative) Instead of computing $x^k/k!$ from scratch each time, update iteratively: ```c double term = 1.0; // x^0 / 0! = 1 for k = 0 to n: sum += term term = term * x / (k+1) // term becomes x^{k+1} / (k+1)! ``` Each iteration does just 2 operations — no power or factorial needed. ### Your Task Implement `double maclaurin_exp(double x, int n)` that computes $sum_{k=0}^n rac{x^k}{k!}$.
TCC compiler loading...
Loading...
Click "Run" to execute your code.