§01 Limits & Continuity
The limit is the single foundational idea on which all of calculus rests. Every derivative is a limit. Every definite integral is a limit. Understanding limits rigorously means understanding calculus at its core.
Formal ε-δ Definition
Example proof (ε-δ): Show limx→3 (2x − 1) = 5.
Limit Laws
The Squeeze Theorem — limx→0 (sin x)/x = 1
This limit is used in every proof about derivatives of trigonometric functions. We prove it geometrically.
Proof via area comparison (0 < x < π/2):
For x → 0⁻: sin(−x)/(−x) = sin x/x, so the two-sided limit is 1.
L'Hôpital's Rule
When a limit gives the indeterminate form 0/0 or ∞/∞, differentiate numerator and denominator separately.
Proof of the 0/0 case (via Cauchy's Mean Value Theorem):
Continuity
f is continuous at a when three conditions all hold: (1) f(a) is defined, (2) limx→a f(x) exists, (3) limx→a f(x) = f(a). A function continuous on a closed interval satisfies both the Extreme Value Theorem and the Intermediate Value Theorem.
Intermediate Value Theorem (IVT)
If f is continuous on [a,b] and N is strictly between f(a) and f(b), then there exists c ∈ (a,b) with f(c) = N.
Proof by nested interval bisection:
GNU Octave — Limits
% ─── Numerical exploration of lim sin(x)/x as x→0 ─────────────── x_vals = [0.5, 0.1, 0.01, 1e-4, 1e-8]; printf("x sin(x)/x\n"); for x = x_vals printf("%.2e %.15f\n", x, sin(x)/x); endfor % Catastrophic cancellation demo — do NOT use tiny h for this limit printf("\nh = 1e-16: sin(h)/h = %.15f (numerical noise!)\n", sin(1e-16)/1e-16); % ─── ε-δ verification: lim_{x→3}(2x−1) = 5 ───────────────────── a = 3; L = 5; epsilon = 0.01; delta = epsilon/2; xs = a + delta*[-0.99, -0.5, 0.5, 0.99]; printf("\nε=%.4f δ=%.4f verification:\n", epsilon, delta); for x = xs fx = 2*x - 1; printf(" x=%.4f f=%.4f |f-L|=%.4f within_ε=%d\n", ... x, fx, abs(fx-L), abs(fx-L) < epsilon); endfor % ─── L'Hôpital: lim sin(x)/x via differentiation ───────────────── % Numerator limit: d/dx sin(x) at 0 = cos(0) = 1 % Denominator lim: d/dx x at 0 = 1 → ratio = 1 printf("\nL'Hopital result: cos(0)/1 = %.15f\n", cos(0)); % ─── IVT: bisection root of f(x)=x³−x−2 on [1,2] ──────────────── function c = bisect(f, a, b, tol) while (b - a)/2 > tol m = (a + b)/2; if f(m) == 0; c = m; return; endif if sign(f(m)) == sign(f(a)); a = m; else; b = m; endif endwhile c = (a + b)/2; endfunction f = @(x) x^3 - x - 2; root = bisect(f, 1, 2, 1e-12); printf("\nBisection root of x³−x−2 = %.14f f(root)=%.2e\n", root, f(root)); % ─── Continuity check: is |x|/x continuous at 0? ───────────────── for x = [-0.01, -1e-10, 0, 1e-10, 0.01] if x == 0; val = 'undef'; else; val = num2str(x/abs(x)); endif printf(" sign(%.2e) = %s\n", x, val); endfor printf("→ Limits from left/right disagree: NOT continuous at 0.\n");
§02 Derivatives — Definition & Rules
The derivative formalises the idea of instantaneous rate of change. Geometrically it is the slope of the tangent line; physically it is velocity, acceleration, or any rate.
The Derivative from First Principles
Proof: d/dx (xⁿ) = nxⁿ⁻¹ (Power Rule, integer n ≥ 1)
Proof: Product Rule — (fg)′ = f′g + fg′
Proof: Quotient Rule — (f/g)′ = (f′g − fg′)/g²
Proof: Chain Rule — [f(g(x))]′ = f′(g(x))·g′(x)
The naive proof divides by Δg, which may be zero. The rigorous version uses an auxiliary ε-function.
Proof: d/dx eˣ = eˣ
Complete Differentiation Table
Implicit Differentiation
Differentiate both sides with respect to x, treating y as an unknown function y(x). Then solve for dy/dx.
Example: Unit circle x² + y² = 1
Differentiate: 2x + 2y(dy/dx) = 0 ⟹ dy/dx = −x/y. The tangent at (x₀,y₀) has slope −x₀/y₀, perpendicular to the radius.
Example: Elliptic curve y² = x³ − x + 1
2y(dy/dx) = 3x² − 1 ⟹ dy/dx = (3x²−1)/(2y). This formula is the group law of elliptic curve cryptography (see §12).
GNU Octave — Derivatives
% ─── Complex-step derivative (machine-precision, no cancellation) ─ % f′(x) ≈ Im[f(x+ih)]/h for tiny h — provably exact to h² function d = csd(f, x) h = 1e-200; d = imag(f(x + 1i*h)) / h; endfunction printf("Complex-step derivative verification:\n"); tests = {'xⁿ', @(x) x^5, @(x) 5*x^4; 'eˣ', @exp, @exp; 'sin x',@sin, @cos; 'ln x', @log, @(x)1/x; 'xln x',@(x)x*log(x), @(x)log(x)+1}; x0 = 1.7; for i = 1:rows(tests) ex = tests{i,3}(x0); nu = csd(tests{i,2}, x0); printf(" d/dx %-8s exact=%+.10f csd=%+.10f err=%.1e\n", ... tests{i,1}, ex, nu, abs(ex-nu)); endfor % ─── Central difference vs complex step accuracy comparison ─────── f = @(x) sin(x.^2) .* exp(-x); fp = @(x) (2*x.*cos(x^2) - sin(x^2)) .* exp(-x); x0 = pi/3; exact = fp(x0); printf("\nError vs step size h:\n"); for h = [1e-1,1e-3,1e-6,1e-9,1e-12] cd_err = abs((f(x0+h)-f(x0-h))/(2*h) - exact); cs_err = abs(csd(@(x)f(x), x0) - exact); % always ~1e-16 regardless of h printf(" h=%.0e central_diff err=%.1e\n", h, cd_err); endfor printf(" complex-step err = %.1e (independent of h)\n", csd(@(x)f(x),x0)-exact); % ─── Chain rule: d/dx sin(x²) = 2x·cos(x²) ────────────────────── g = @(x) sin(x.^2); gp = @(x) 2*x.*cos(x.^2); for x = [0.5, 1, pi/4] printf(" d/dx sin(x²)|x=%.3f: exact=%+.10f csd=%+.10f\n", x, gp(x), csd(g,x)); endfor % ─── Implicit diff: slope of ellipse 3x²+2y²=5 at (1,1) ────────── % dy/dx = −3x/(2y) x0=1; y0=1; slope = -3*x0/(2*y0); printf("\nImplicit: slope of 3x²+2y²=5 at (1,1): dy/dx = %.6f\n", slope);
§03 Derivatives of Trigonometric Functions
Proof: d/dx (sin x) = cos x
Proof: d/dx (cos x) = −sin x
Proof: d/dx (tan x) = sec²x
Proof: d/dx (sec x) = sec x tan x
All Six Trigonometric Derivatives
Inverse Trigonometric Derivatives — all from Implicit Differentiation
Proof: d/dx (arctan x) = 1/(1+x²)
Proof: d/dx (arcsin x) = 1/√(1−x²)
The d/dx Cycle: Higher Derivatives of Sine
The pattern: sin → cos → −sin → −cos → sin → … cycles with period 4. In compact form: the nth derivative of sin x equals sin(x + nπ/2), verifiable by noting that differentiation multiplies the Fourier transform by iω, i.e., by e^{iπ/2} = i.
GNU Octave — Trig Derivatives
% ─── Verify all 6 trig derivatives at x = π/5 ──────────────────── function d = csd(f, x); d = imag(f(x+1e-200i))*1e200; endfunction x = pi/5; rules = {'sin x', @sin, @cos; 'cos x', @cos, @(x)-sin(x); 'tan x', @tan, @(x)1/cos(x)^2; 'csc x', @csc, @(x)-csc(x)*cot(x); 'sec x', @sec, @(x)sec(x)*tan(x); 'cot x', @cot, @(x)-csc(x)^2}; printf("Trig derivative verification at x=π/5:\n"); for i=1:rows(rules) ex = rules{i,3}(x); nu = csd(rules{i,2}, x); printf(" d/dx %-7s exact=%+.10f csd=%+.10f err=%.1e\n", ... rules{i,1}, ex, nu, abs(ex-nu)); endfor % ─── Verify inverse trig derivatives ────────────────────────────── printf("\nInverse trig derivatives:\n"); iv = {'arcsin', @asin, @(x)1/sqrt(1-x^2); 'arccos', @acos, @(x)-1/sqrt(1-x^2); 'arctan', @atan, @(x)1/(1+x^2)}; x2 = 0.4; for i=1:3 ex = iv{i,3}(x2); nu = csd(iv{i,2}, x2); printf(" d/dx %-8s at 0.4: exact=%+.10f csd=%+.10f err=%.1e\n", ... iv{i,1}, ex, nu, abs(ex-nu)); endfor % ─── nth derivative of sin: d^n/dx^n sin(x) = sin(x + n*π/2) ───── x0 = pi/3; printf("\nnth derivative of sin x at x=π/3:\n"); for n = 0:7 val = sin(x0 + n*pi/2); printf(" n=%d: sin(x+nπ/2) = %+.8f\n", n, val); endfor % ─── Tricky chain rule: d/dx sin(cos(x)) ───────────────────────── f = @(x)sin(cos(x)); fp = @(x)cos(cos(x)).*(-sin(x)); x_grid = linspace(0,2*pi,5); printf("\nd/dx sin(cos(x)):\n"); for xv = x_grid printf(" x=%.4f exact=%+.8f csd=%+.8f\n", xv, fp(xv), csd(f,xv)); endfor % ─── Plot: sin, cos and their derivatives ───────────────────────── x = linspace(-2*pi, 2*pi, 1000); figure('Name','Trig Derivatives'); plot(x,sin(x),'b-','lw',2, x,cos(x),'r--','lw',2); legend('sin x',"d/dx sin x = cos x"); grid on; title('sin x and its derivative');
§04 Applications of Derivatives
Mean Value Theorem (MVT)
If f is continuous on [a,b] and differentiable on (a,b), then there exists c ∈ (a,b) such that:
Interpretation: the instantaneous rate of change equals the average rate of change at some interior point.
Proof via Rolle's Theorem (which is MVT when f(a)=f(b)):
Critical Points, Extrema, Concavity
First Derivative Test
At critical point c (f′(c)=0 or undefined):
- f′ changes + to − : local max
- f′ changes − to + : local min
- No sign change: saddle point
Second Derivative Test
- f″(c) > 0 : local minimum (concave up ∪)
- f″(c) < 0 : local maximum (concave down ∩)
- f″(c) = 0 : inconclusive
Inflection Points
Points where f″ changes sign — where concavity flips. Test: solve f″(x) = 0 and check sign change.
Newton-Raphson Method
Use the tangent line to iteratively improve a root estimate. Each step replaces the curve with its tangent:
Converges quadratically near a simple root: the error squares at each step, so correct digits roughly double per iteration.
Related Rates
Classic: Sliding Ladder
A 10-m ladder leans against a wall. The foot slides outward at 2 m/s. How fast does the top slide down when the foot is 6 m from the wall?
Expanding Oil Slick (circle area)
A = πr². Differentiate: dA/dt = 2πr · (dr/dt). If r=5 m and dr/dt=0.3 m/min, then dA/dt = 3π ≈ 9.42 m²/min.
Linearisation & Differentials
The differential df = f′(x) dx quantifies the approximate change in output for a small change dx in input. This is the basis of error propagation in physics and engineering.
GNU Octave — Optimization & Newton-Raphson
% ─── Newton-Raphson with convergence tracking ───────────────────── function [root,iters,errs] = newton(f, fp, x0, tol) x = x0; errs = []; for k = 1:50 fx = f(x); errs(end+1) = abs(fx); if abs(fx) < tol; root=x; iters=k; return; endif x = x - fx/fp(x); endfor root=x; iters=50; endfunction % Find √2: solve x²−2=0 f = @(x)x^2-2; fp = @(x)2*x; [r,k,e] = newton(f, fp, 1.5, 1e-15); printf("√2 by Newton-Raphson:\n"); for i=1:length(e) printf(" iter %d: |f|=%.3e (digits ≈ %.1f)\n", i, e(i), -log10(e(i)+1e-16)); endfor printf(" Result: %.15f error=%.2e\n", r, abs(r-sqrt(2))); % Quadratic convergence: each step squares the error printf("\nConvergence ratio |eₙ₊₁|/|eₙ|²:\n"); for i=1:length(e)-2 printf(" step %d→%d: %.4f (should→constant)\n", i, i+1, e(i+1)/e(i)^2); endfor % ─── Optimize f(x) = x⁴−4x²+x using Newton on f′=0 ────────────── f2 = @(x) x^4 - 4*x^2 + x; fp2 = @(x) 4*x^3 - 8*x + 1; fpp = @(x) 12*x^2 - 8; printf("\nCritical points of x⁴−4x²+x:\n"); for x0 = [-1.5, 0.1, 1.6] [r,~,~] = newton(fp2, fpp, x0, 1e-13); typ = '?'; if fpp(r)>0; typ='min'; elseif fpp(r)<0; typ='max'; endif printf(" x₀=%.2f → x*=%.8f f=%.6f f''=%.4f → %s\n", x0,r,f2(r),fpp(r),typ); endfor % ─── Linearisation: approximate sin(0.1) near a=0 ──────────────── a = 0; printf("\nLinearisation of sin(x) near x=0:\n"); for h = [0.1, 0.3, 0.5, 1.0] lin = sin(a) + cos(a)*(h - a); % = h (since sin(0)=0, cos(0)=1) exact = sin(h); printf(" x=%.1f: linear=%.6f exact=%.6f err=%.2e\n", h, lin, exact, abs(lin-exact)); endfor
§05 Integration & the Fundamental Theorem
The definite integral is defined as the limit of Riemann sums. The Fundamental Theorem of Calculus (FTC) connects differentiation and integration — arguably the most important result in all of mathematics.
The Riemann Integral
Partition [a,b] into n subintervals of width Δx = (b−a)/n. Choose sample points xi* in each subinterval:
Fundamental Theorem of Calculus — Part 1
Proof of FTC Part 1:
Fundamental Theorem of Calculus — Part 2
Proof of FTC Part 2:
Standard Antiderivatives
Properties of Definite Integrals
Numerical Integration: Trapezoid & Simpson's Rules
GNU Octave — Integration
% ─── Riemann sums: left, midpoint, right ───────────────────────── function s = riemann(f, a, b, n, rule) h = (b-a)/n; switch rule case 'left'; xs = a + (0:n-1)*h; case 'right'; xs = a + (1:n)*h; case 'mid'; xs = a + (0.5:1:n-0.5)*h; endswitch s = h * sum(f(xs)); endfunction f = @(x) sin(x) + 1.2; a=0; b=pi; exact = quadgk(f, a, b); printf("∫₀^π (sin x + 1.2) dx = %.15f\n", exact); printf("\nRiemann sum convergence:\n"); for n = [5, 20, 100, 1000] L = riemann(f,a,b,n,'left'); M = riemann(f,a,b,n,'mid'); printf(" n=%4d: left=%.8f mid=%.8f mid_err=%.2e\n", n,L,M,abs(M-exact)); endfor % ─── Composite trapezoid and Simpson's ─────────────────────────── function s = trapz_rule(f,a,b,n) x = linspace(a,b,n+1); h=(b-a)/n; s = h/2*(f(x(1))+2*sum(f(x(2:end-1)))+f(x(end))); endfunction function s = simpsons(f,a,b,n) % n must be even x = linspace(a,b,n+1); h=(b-a)/n; s = h/3*(f(x(1)) + 4*sum(f(x(2:2:end-1))) + 2*sum(f(x(3:2:end-2))) + f(x(end))); endfunction g = @(x) exp(-x.^2/2) / sqrt(2*pi); % Gaussian PDF exact_g = quadgk(g, -3, 3); printf("\nGaussian CDF P(|X|<3) via quadrature:\n"); printf(" exact = %.15f\n", exact_g); printf(" trapz (n=100) err = %.2e\n", abs(trapz_rule(g,-3,3,100)-exact_g)); printf(" Simp (n=100) err = %.2e\n", abs(simpsons(g,-3,3,100)-exact_g)); % ─── FTC Part 1 demo: d/dx ∫₀ˣ sin(t²) dt ≈ sin(x²) ───────────── F = @(x) quadgk(@(t)sin(t.^2), 0, x); Fp = @(x) sin(x^2); % FTC Part 1 prediction h = 1e-5; x0 = 1.3; numerical_deriv = (F(x0+h) - F(x0-h))/(2*h); printf("\nFTC Part 1: d/dx ∫₀ˣ sin(t²)dt at x=1.3:\n"); printf(" FTC prediction sin(x²) = %.10f\n", Fp(x0)); printf(" Numerical deriv of F(x) = %.10f\n", numerical_deriv);
§06 Integration of Trigonometric Functions
Basic Trig Integrals
Proof: ∫ tan x dx = −ln|cos x| + C
Proof: ∫ sec x dx = ln|sec x + tan x| + C
Power Reduction: Even Powers of Sine and Cosine
Proof: ∫₀2π sin²x dx = π
Trig Substitution
| Integral contains | Substitution | Identity used | Range |
|---|---|---|---|
| √(a²−x²) | x = a sin θ | 1 − sin²θ = cos²θ | θ ∈ [−π/2, π/2] |
| √(a²+x²) | x = a tan θ | 1 + tan²θ = sec²θ | θ ∈ (−π/2, π/2) |
| √(x²−a²) | x = a sec θ | sec²θ − 1 = tan²θ | θ ∈ [0, π/2) |
The Gaussian Integral — Proof via Polar Coordinates
Proof — the most elegant computation in analysis (uses trig via polar coords):
Fourier Orthogonality — Foundation of Signal Processing & Cryptography
Proof (m ≠ n):
GNU Octave — Trig Integration
% ─── Verify all basic trig integrals ───────────────────────────── tests = {'∫ sin', @sin, @(x)-cos(x); '∫ cos', @cos, @sin; '∫ sec²', @(x)sec(x).^2, @tan; '∫ sec·tan', @(x)sec(x).*tan(x), @sec}; a=0.3; b=1.1; printf("Trig integral verification [%.1f, %.1f]:\n", a, b); for i=1:rows(tests) ftc = tests{i,3}(b) - tests{i,3}(a); num = quadgk(tests{i,2}, a, b); printf(" %-12s FTC=%.10f quad=%.10f err=%.1e\n", ... tests{i,1}, ftc, num, abs(ftc-num)); endfor % ─── Fourier orthogonality: ∫₀^2π sin(mx)sin(nx) dx ───────────── printf("\nFourier inner products (should be π on diagonal, 0 off):\n"); for m=1:4 for n=1:4 v = quadgk(@(x)sin(m*x).*sin(n*x), 0, 2*pi); printf("%6.3f", v/pi); endfor; printf("\n"); endfor % ─── Gaussian integral: ∫_{-∞}^{∞} e^{-x²} dx = √π ───────────── I = quadgk(@(x)exp(-x.^2), -30, 30); printf("\n∫e^(-x²)dx = %.15f √π = %.15f\n", I, sqrt(pi)); % ─── Power reduction: ∫₀^π sin⁴(x)dx = 3π/8 ──────────────────── I4 = quadgk(@(x)sin(x).^4, 0, pi); printf("∫₀^π sin⁴x dx = %.12f (3π/8=%.12f)\n", I4, 3*pi/8); % ─── Trig substitution: ∫₀^1 √(1−x²)dx = π/4 (unit semicircle) ─ Iq = quadgk(@(x)sqrt(1-x.^2), 0, 1); printf("∫₀^1 √(1−x²)dx = %.15f (π/4=%.15f)\n", Iq, pi/4); % ─── Wallis product: ∫₀^{π/2} sinⁿ dx via reduction formula ────── function W = wallis(n) if n==0; W=pi/2; elseif n==1; W=1; else; W=(n-1)/n*wallis(n-2); endif endfunction printf("\nWallis integrals ∫₀^{π/2} sinⁿ(x) dx:\n"); for n=0:6 printf(" n=%d: formula=%.8f quad=%.8f\n", n, wallis(n), ... quadgk(@(x)sin(x).^n, 0, pi/2)); endfor
§07 Integration Techniques
u-Substitution (Reverse Chain Rule)
Integration by Parts (IBP)
Proof from the Product Rule:
LIATE priority for choosing u:
Logarithm → Inverse trig → Algebraic (polynomial) → Trig → Exponential
Example: ∫ x ex dx — choose u=x (Algebraic), dv=exdx → ∫ x eˣ dx = xeˣ − eˣ + C.
Reduction Formula for ∫ sinⁿx dx
Proof via integration by parts:
Partial Fractions
For rational P(x)/Q(x) with deg P < deg Q, decompose Q into factors:
Linear factor (x−a)
A/(x−a)
Repeated (x−a)ⁿ
A₁/(x−a) + … + Aₙ/(x−a)ⁿ
Irreducible quadratic
(Ax+B)/(x²+bx+c)
Worked Example: ∫ x sin x dx
Worked Example: ∫ ln x dx
GNU Octave — Integration Techniques
% ─── IBP: ∫ x·sin(x) dx = −x·cos(x) + sin(x) ──────────────────── antideriv = @(x) -x.*cos(x) + sin(x); printf("∫₀^π x·sin(x) dx:\n"); printf(" FTC: %.15f (exact: π=%.15f)\n", antideriv(pi)-antideriv(0), pi); printf(" quad: %.15f\n", quadgk(@(x)x.*sin(x), 0, pi)); % ─── IBP: ∫ x²·eˣ dx (needs IBP twice) ────────────────────────── % Antideriv: eˣ(x²−2x+2) A2 = @(x) exp(x).*(x.^2 - 2*x + 2); printf("\n∫₀^1 x²·eˣ dx:\n"); printf(" FTC: %.15f\n", A2(1)-A2(0)); printf(" quad: %.15f\n", quadgk(@(x)x.^2.*exp(x), 0, 1)); % ─── Reduction formula verification ────────────────────────────── function W = wallis(n) if n==0; W=pi/2; elseif n==1; W=1; else; W=(n-1)/n*wallis(n-2); endif endfunction printf("\nReduction formula ∫₀^{π/2} sinⁿx dx:\n"); for n = [2,4,6,8] w = wallis(n); q = quadgk(@(x)sin(x).^n, 0, pi/2); printf(" n=%d: formula=%.10f quad=%.10f err=%.1e\n", n, w, q, abs(w-q)); endfor % ─── Partial fractions: ∫ 1/(x²−1) dx ─────────────────────────── % 1/(x²−1) = (1/2)/(x−1) − (1/2)/(x+1) % Antideriv = (1/2)·ln|(x−1)/(x+1)| A3 = @(x) 0.5*log(abs((x-1)./(x+1))); I_pf = quadgk(@(x)1./(x.^2-1), 2, 5); I_ftc = A3(5) - A3(2); printf("\n∫₂^5 1/(x²−1) dx: quad=%.12f FTC=%.12f err=%.1e\n", I_pf, I_ftc, abs(I_pf-I_ftc)); % ─── u-sub: ∫ x·√(x²+1) dx = (x²+1)^{3/2}/3 ──────────────────── A4 = @(x) (x.^2+1).^(3/2)/3; printf("∫₀^2 x√(x²+1) dx: FTC=%.10f quad=%.10f\n", ... A4(2)-A4(0), quadgk(@(x)x.*sqrt(x.^2+1), 0, 2));
§08 Taylor & Maclaurin Series
Taylor series let us represent smooth functions as infinite polynomials. They connect differentiation, integration, and exponential/trig functions through a single algebraic framework.
Taylor's Theorem with Remainder
Proof via repeated Integration by Parts:
Essential Maclaurin Series (a = 0)
Proof: sin x = x − x³/3! + x⁵/5! − …
Euler's Formula — Proved by Taylor Series
Leibniz Formula for π
GNU Octave — Taylor Series & Euler
% ─── Taylor series for sin x: convergence ──────────────────────── function s = taylor_sin(x, N) s = 0; for n = 0:N-1 s = s + (-1)^n * x^(2*n+1) / factorial(2*n+1); endfor endfunction x = pi/3; printf("Taylor sin(π/3) convergence:\n"); for N = 1:9 ap = taylor_sin(x, N); printf(" N=%d: %.15f err=%.2e\n", N, ap, abs(ap-sin(x))); endfor % ─── Euler's formula: e^{iθ} = cos θ + i sin θ ─────────────────── theta = pi/5; lhs = exp(1i*theta); rhs = cos(theta) + 1i*sin(theta); printf("\nEuler e^{iπ/5}: LHS=%.10f%+.10fi\n", real(lhs), imag(lhs)); printf(" RHS=%.10f%+.10fi\n", real(rhs), imag(rhs)); printf(" e^{iπ}+1 = %.2e + %.2ei (should be 0)\n", ... real(exp(1i*pi)+1), imag(exp(1i*pi)+1)); % ─── Leibniz series and faster Machin formula for π ────────────── printf("\nLeibniz π/4 partial sums:\n"); s = 0; for n=0:9 s = s + (-1)^n/(2*n+1); printf(" n=%d: 4s=%.10f err=%.2e\n", n, 4*s, abs(4*s-pi)); endfor % Machin: π/4 = 4·atan(1/5) − atan(1/239) — converges far faster pi_machin = 4*(4*atan(1/5) - atan(1/239)); printf("Machin π=%.15f err=%.2e\n", pi_machin, abs(pi_machin-pi)); % ─── Taylor coefficients via FFT (Cauchy's coefficient formula) ── function c = taylor_fft(f, a, n, r) % c(k) = f^(k)(a)/k! via |f(a+r·e^{2πij/N})|/N N = max(256, 2^ceil(log2(n+1))); th = 2*pi*(0:N-1)/N; z = a + r*exp(1i*th); fv = arrayfun(f, z); cf = real(ifft(fv)); c = cf(1:n+1) ./ (r.^(0:n)); endfunction c = taylor_fft(@sin, 0, 8, 1); printf("\nTaylor coefficients of sin(x) at 0 (via FFT):\n"); for k=0:8 if abs(c(k+1))>1e-10 printf(" k=%d: %.10f (1/k!=%.10f)\n", k, c(k+1), (-1)^((k-1)/2)/factorial(k)); endif endfor
§09 Ordinary Differential Equations
Separation of Variables
Proof: General solution of y′ = ky (exponential growth/decay)
First-Order Linear ODE: Integrating Factor Method
Derivation:
Second-Order Linear ODEs: Characteristic Equation
Two distinct real roots r₁ ≠ r₂
y = C₁er₁x + C₂er₂x
Repeated root r = r₁ = r₂
y = (C₁ + C₂x)erx
Complex roots r = α ± βi
y = eαx[C₁cos(βx) + C₂sin(βx)]
Simple Harmonic Oscillator (SHO)
Proof that y = sin(ωt) satisfies y″ + ω²y = 0:
Damped Oscillator
Underdamped (c² < 4mk)
Oscillates with decaying envelope: e−αt[C₁cos(βt)+C₂sin(βt)]
Critically damped (c²=4mk)
Fastest return: (C₁+C₂t)e−αt
Overdamped (c²>4mk)
No oscillation: C₁er₁t+C₂er₂t, r₁,r₂ < 0
The Logistic Equation
Models population growth with carrying capacity K. Separable ODE; its S-shaped solution curve is a fundamental shape in biology, epidemiology, and machine learning (the sigmoid function).
GNU Octave — ODEs
% ─── Exponential decay: y'=−0.5y, y(0)=3 ──────────────────────── [t,y] = ode45(@(t,y)-0.5*y, [0 10], 3); exact = @(t) 3*exp(-0.5*t); err = max(abs(y - exact(t))); printf("Decay y'=−0.5y: max ode45 err = %.2e\n", err); % ─── SHO: y''+4y=0, y(0)=1, y'(0)=0 → y=cos(2t) ───────────────── sho = @(t,y)[y(2); -4*y(1)]; [ts,ys] = ode45(sho, [0 4*pi], [1;0]); err_sho = max(abs(ys(:,1) - cos(2*ts))); printf("SHO y''+4y=0: max err vs cos(2t) = %.2e\n", err_sho); % ─── Damped oscillator: y''+2cy'+4y=0 for c=0.3,2,4 ───────────── printf("\nDamped oscillator at t=10:\n"); for c = [0.3, 2, 4] ode = @(t,y)[y(2); -2*c*y(2)-4*y(1)]; [td,yd] = ode45(ode,[0 10],[1;0]); disc = (2*c)^2 - 16; if disc<0; typ='under'; elseif disc==0; typ='crit'; else; typ='over'; endif printf(" c=%.1f (%sdamped): y(10)=%.6f\n", c, typ, interp1(td,yd(:,1),10)); endfor % ─── Logistic equation ──────────────────────────────────────────── r=1.5; K=100; P0=5; logistic_exact = @(t) K ./ (1 + (K-P0)/P0 * exp(-r*t)); [tl,Pl] = ode45(@(t,P)r*P*(1-P/K), [0 8], P0); err_log = max(abs(Pl - logistic_exact(tl))); printf("\nLogistic: P(8)=%.4f exact=%.4f err=%.2e\n", ... Pl(end), logistic_exact(8), err_log); % ─── Lotka-Volterra (predator-prey) ────────────────────────────── a=1.5; b=1; d=3; g=1; lv = @(t,y)[a*y(1)-b*y(1)*y(2); d*y(1)*y(2)-g*y(2)]; [tlv,ylv] = ode45(lv,[0 15],[1;0.5]); figure('Name','Predator-Prey'); plot(tlv,ylv(:,1),'b-','lw',2, tlv,ylv(:,2),'r-','lw',2); legend('Prey','Predator'); grid on; title('Lotka-Volterra equations');
§10 Multivariable Calculus
Partial Derivatives
Clairaut's Theorem: Symmetry of Mixed Partials
Proof sketch:
The Gradient, Divergence, Curl, Laplacian
Critical Points in 2D — Hessian Test
D > 0, fxx > 0
Local minimum
D > 0, fxx < 0
Local maximum
D < 0
Saddle point
D = 0
Test inconclusive
Green's and Stokes' Theorems
Green's theorem is a 2D special case of Stokes'. Both connect a line integral around a boundary to a flux integral over the enclosed surface — a profound connection between local and global behaviour.
Lagrange Multipliers
Proof intuition:
GNU Octave — Multivariable Calculus
% ─── Partial derivatives via complex step ──────────────────────── f = @(x,y) sin(x.*y) + x.^2.*cos(y); h = 1e-200; x0 = pi/4; y0 = pi/3; dfdx_num = imag(f(x0+1i*h, y0))/h; dfdy_num = imag(f(x0, y0+1i*h))/h; % Exact: ∂f/∂x = y·cos(xy)+2x·cos(y), ∂f/∂y = x·cos(xy)−x²·sin(y) dfdx_ex = y0*cos(x0*y0)+2*x0*cos(y0); dfdy_ex = x0*cos(x0*y0)-x0^2*sin(y0); printf("∂f/∂x: exact=%.12f cs=%.12f err=%.1e\n", dfdx_ex, dfdx_num, abs(dfdx_ex-dfdx_num)); printf("∂f/∂y: exact=%.12f cs=%.12f err=%.1e\n", dfdy_ex, dfdy_num, abs(dfdy_ex-dfdy_num)); % ─── Gradient descent on f(x,y) = x²+2y²−xy+x ─────────────────── f2 = @(v) v(1)^2 + 2*v(2)^2 - v(1)*v(2) + v(1); grad = @(v) [2*v(1)-v(2)+1; 4*v(2)-v(1)]; v = [4;3]; lr = 0.08; printf("\nGradient descent (lr=0.08):\n"); for k=1:40 v = v - lr*grad(v); if mod(k,8)==0 printf(" k=%2d: v=[%.6f,%.6f] f=%.8f |∇|=%.2e\n",... k, v(1),v(2), f2(v), norm(grad(v))); endif endfor % Exact: ∇f=0 → 2x−y+1=0, 4y−x=0 → x=−4/7, y=−1/7 printf(" Exact min: x=%.8f, y=%.8f\n", -4/7, -1/7); % ─── Hessian test for f(x,y)=x³−3x+y³−3y ──────────────────────── % Critical pts: 3x²−3=0 → x=±1; 3y²−3=0 → y=±1 printf("\nHessian classification of x³−3x+y³−3y:\n"); for cx = [-1,1] for cy = [-1,1] fxx=6*cx; fyy=6*cy; fxy=0; D = fxx*fyy - fxy^2; if D>0&&fxx>0; t='min'; elseif D>0&&fxx<0; t='max'; else; t='saddle'; endif fval = cx^3-3*cx+cy^3-3*cy; printf(" (%+d,%+d): D=%.1f → %s f=%.1f\n", cx,cy,D,t,fval); endfor endfor % ─── Laplace's equation solver (finite differences) ────────────── N=25; u=zeros(N); u(end,:) = sin(linspace(0,pi,N)); % top BC: u=sin(πx) for iter=1:3000 u(2:end-1,2:end-1) = ... (u(1:end-2,2:end-1)+u(3:end,2:end-1)+ ... u(2:end-1,1:end-2)+u(2:end-1,3:end))/4; endfor % Exact: u(x,y) = sin(πx)·sinh(πy)/sinh(π) exact_u = @(x,y) sin(pi*x).*sinh(pi*y)/sinh(pi); x_pts = linspace(0,1,N); y_pts = x_pts; [Xg,Yg] = meshgrid(x_pts, y_pts); err_laplace = max(abs(u(:) - exact_u(Xg(:),Yg(:)))); printf("\nLaplace solver (25×25 grid) max error: %.3e\n", err_laplace);
§11 Complex Analysis & Calculus
11.1 — Complex Differentiation & the Cauchy–Riemann Equations
Let f(z) = u(x,y) + iv(x,y) where z = x + iy. The function f is complex-differentiable (holomorphic) at z₀ if the limit
exists regardless of the direction h approaches 0 in the complex plane.
11.2 — Harmonic Functions
Harmonic functions model steady-state heat, electrostatics, and fluid flow — the Laplace PDE solver in §13 computes them numerically.
11.3 — Cauchy's Integral Theorem & Formula
11.4 — Laurent Series & the Residue Theorem
Near an isolated singularity z₀, f has a Laurent expansion:
The coefficient a₋₁ is the residue of f at z₀:
11.5 — Evaluating Real Integrals via Residues
11.6 — Conformal Mappings
A holomorphic function with f′(z₀) ≠ 0 preserves angles at z₀ — it is conformal. Key maps:
| Map | Formula | Effect |
|---|---|---|
| Möbius | w = (az+b)/(cz+d) | Maps circles/lines to circles/lines |
| Joukowski | w = z + 1/z | Circle → airfoil shape (aerodynamics) |
| Exponential | w = ez | Horizontal strip → wedge/sector |
| Schwarz–Christoffel | dw/dz = C·∏(z−xk)αk−1 | Upper half-plane → polygon |
Cryptographic note: conformal maps on elliptic curves (§12) transform the group law while preserving algebraic structure — the basis of isogeny-based post-quantum cryptography.
§12 Cryptography — The Calculus of Security
12.1 — Information Entropy & Lagrange Multipliers
Shannon entropy measures uncertainty in a probability distribution {p₁,…,pₙ}:
Cryptographic meaning: A truly random key of n symbols carries H = ln n bits of entropy — any non-uniform distribution leaks information an attacker can exploit.
12.2 — Continuous Probability & the CDF
For a continuous random variable X with PDF f(x):
The normal distribution N(μ,σ²) has PDF (1/σ√(2π)) e−(x−μ)²/(2σ²). Its integral has no closed form — the error function erf(x) = (2/√π)∫₀ˣ e−t² dt is computed numerically.
12.3 — Elliptic Curve Cryptography: Group Law via Implicit Differentiation
An elliptic curve E: y² = x³ + ax + b defines a group. The tangent-and-chord addition rule uses calculus directly.
Point addition (P ≠ Q): slope m = (y₂−y₁)/(x₂−x₁), then same formulas. The scalar multiplication kP = P+P+⋯+P (k times) via double-and-add is the trapdoor: computing kP is fast (O(log k) doublings), but recovering k from kP is the Elliptic Curve Discrete Logarithm Problem (ECDLP) — believed intractable.
12.4 — RSA & Euler's Theorem
RSA construction: Choose primes p, q; n = pq; φ(n) = (p−1)(q−1). Pick e with gcd(e,φ(n))=1; compute d ≡ e⁻¹ mod φ(n). Encrypt: c = mᵉ mod n. Decrypt: m = cd = med = m1+kφ(n) = m · (mφ(n))k ≡ m · 1k = m (mod n).
12.5 — Differential Privacy: The Laplace Mechanism
To publish a numeric query f(D) on a dataset D without revealing any individual, add Laplace noise:
where Δf = maxD,D′ |f(D) − f(D′)| is the sensitivity (over neighbouring datasets) and ε is the privacy budget.
12.6 — Hash Functions & Sensitivity to Initial Conditions
Cryptographic hash functions (SHA-256, BLAKE3) are designed so that changing one input bit cascades unpredictably — the avalanche effect. This mirrors sensitivity to initial conditions in dynamical systems:
where λ > 0 is the Lyapunov exponent. The exponential function (whose derivative equals itself: (eˣ)′ = eˣ from §2) is the engine of both chaotic divergence and cryptographic diffusion.
12.7 — Lattice Cryptography & Gaussian Distributions
Post-quantum lattice schemes (CRYSTALS-Kyber, CRYSTALS-Dilithium) sample error vectors from a discrete Gaussian over a lattice Λ:
The smoothing parameter ηε(Λ) — the σ at which the Gaussian "smears" over Λ so that its distribution is nearly uniform modulo the fundamental domain — is computed via the Poisson summation formula, which itself relies on the Fourier transform (integration from §5–§7).
12.8 — Zero-Knowledge Proofs & the Schwartz–Zippel Lemma
A ZK-SNARK proves knowledge of a secret without revealing it. At its core lies polynomial identity testing:
In a ZK-SNARK, the prover commits to a polynomial encoding the computation. The verifier picks a random evaluation point r. If the polynomial is wrong, it will disagree with probability ≥ 1 − d/|𝔽| — overwhelming for a large field.
% --- 12A: Shannon Entropy --- p = [0.5 0.25 0.125 0.125]; H = -sum(p .* log2(p)); printf("Shannon entropy: %.4f bits (max = %.4f for n=%d)\n", H, log2(length(p)), length(p)); % --- 12B: ECC Point Doubling on y²=x³+2x+3 (mod 97) --- a = 2; p_mod = 97; P = [3, 6]; % verify: 6²=36 ≡ 3³+2·3+3=36 (mod 97) ✓ m = mod((3*P(1)^2 + a) * power_mod(2*P(2), p_mod-2, p_mod), p_mod); function r = power_mod(base, exp, m) r = 1; base = mod(base, m); while exp > 0 if mod(exp,2) == 1, r = mod(r*base, m); end exp = floor(exp/2); base = mod(base*base, m); end end x3 = mod(m^2 - 2*P(1), p_mod); y3 = mod(m*(P(1)-x3) - P(2), p_mod); printf("ECC double: 2·(%d,%d) = (%d,%d) on y²=x³+2x+3 mod 97\n", P(1),P(2),x3,y3); % --- 12C: Differential Privacy — Laplace Mechanism --- true_mean = 50; sensitivity = 1; epsilon = 0.5; n_releases = 10000; noise = -sensitivity/epsilon .* sign(rand(n_releases,1)-0.5) .* log(1-2*abs(rand(n_releases,1)-0.5)); dp_vals = true_mean + noise; printf("DP mechanism (ε=%.1f): mean=%.3f, std=%.3f\n", epsilon, mean(dp_vals), std(dp_vals)); % --- 12D: Lyapunov Exponent of Logistic Map --- r = 3.9; x = 0.1; N = 10000; lyap = 0; for k = 1:N lyap = lyap + log(abs(r - 2*r*x)); % derivative of rx(1-x) is r-2rx x = r*x*(1-x); end lyap = lyap / N; printf("Logistic map (r=%.1f) Lyapunov exponent: %.4f (chaotic if >0)\n", r, lyap);
§13 GNU Octave — Calculus Laboratory
13.1 — Numerical Differentiation: Complex-Step Method
The classical finite difference f′(x) ≈ [f(x+h)−f(x)]/h suffers from cancellation error for small h. The complex-step derivative avoids this entirely:
% Complex-step: machine-precision derivatives with one function eval function d = complex_step(f, x, h) if nargin < 3, h = 1e-20; end d = imag(f(x + 1i*h)) / h; end f = @(x) sin(x).^3 .* exp(-x.^2); x0 = 1.0; d_cs = complex_step(f, x0); d_exact = 3*sin(x0)^2*cos(x0)*exp(-x0^2) - 2*x0*sin(x0)^3*exp(-x0^2); printf("Complex-step: %.15f\nExact: %.15f\nError: %.2e\n", d_cs, d_exact, abs(d_cs-d_exact));
13.2 — Taylor Coefficients via FFT
% Extract Taylor coefficients of f(z) around z₀ using Cauchy's formula + FFT function c = taylor_fft(f, z0, r, N) % f = function handle, z0 = center, r = radius, N = number of terms theta = 2*pi*(0:N-1)/N; z = z0 + r*exp(1i*theta); c = fft(f(z)) / N; c = c ./ (r.^(0:N-1)); % scale by r^(-n) c = real(c); % clean roundoff for real-analytic functions end % Test: Taylor of e^x around 0 (should give 1/n!) c = taylor_fft(@exp, 0, 1, 10); exact = 1 ./ factorial(0:9); printf("Taylor of exp(x): FFT vs exact:\n"); for k = 0:9 printf(" a_%d = %12.8f (exact %12.8f)\n", k, c(k+1), exact(k+1)); end
13.3 — Gradient Descent: Minimizing a Function
% Gradient descent on Rosenbrock: f(x,y) = (1-x)² + 100(y-x²)² f = @(v) (1-v(1))^2 + 100*(v(2)-v(1)^2)^2; gf = @(v) [-2*(1-v(1)) - 400*v(1)*(v(2)-v(1)^2); 200*(v(2)-v(1)^2)]; x = [-1; 1]; path = x'; for iter = 1:20000 g = gf(x); if norm(g) < 1e-8, break; end % Backtracking line search alpha = 1; rho = 0.5; c1 = 1e-4; while f(x - alpha*g) > f(x) - c1*alpha*(g'*g) alpha = rho * alpha; end x = x - alpha*g; if mod(iter,2000)==0, path = [path; x']; end end printf("Rosenbrock min at (%.6f, %.6f), f=%.2e after %d iters\n", x(1), x(2), f(x), iter);
13.4 — Spectral Differentiation (Chebyshev)
% Spectral differentiation matrix on Chebyshev points N = 20; j = (0:N)'; x = cos(pi*j/N); % Chebyshev-Lobatto points c = [2; ones(N-1,1); 2] .* (-1).^j; X = repmat(x, 1, N+1); dX = X - X'; D = (c * (1./c)') ./ (dX + eye(N+1)); D = D - diag(sum(D, 2)); % Test on f(x) = sin(πx): f'(x) = π cos(πx) fv = sin(pi*x); df_spectral = D * fv; df_exact = pi * cos(pi*x); printf("Chebyshev spectral diff max error: %.3e\n", max(abs(df_spectral - df_exact)));
13.5 — ODE Solvers: Runge-Kutta 4
% θ'' + γθ' + (g/L)sin(θ) = 0 → system: y=[θ, θ'] g = 9.81; L = 1.0; gamma = 0.5; dydt = @(t,y) [y(2); -gamma*y(2) - (g/L)*sin(y(1))]; h = 0.01; T = 15; t = 0:h:T; y = zeros(length(t), 2); y(1,:) = [pi/2, 0]; % initial: 90° release for n = 1:length(t)-1 k1 = dydt(t(n), y(n,:)'); k2 = dydt(t(n)+h/2, y(n,:)' + h/2*k1); k3 = dydt(t(n)+h/2, y(n,:)' + h/2*k2); k4 = dydt(t(n)+h, y(n,:)' + h*k3); y(n+1,:) = y(n,:) + (h/6)*(k1 + 2*k2 + 2*k3 + k4)'; end printf("Damped pendulum (γ=%.1f): final θ=%.4f rad at t=%.0f s\n", gamma, y(end,1), T); printf("Energy dissipated: initial KE+PE = %.4f J\n", g*L*(1-cos(y(1,1))));
13.6 — Monte Carlo Integration
% --- Monte Carlo π via quarter-circle --- N = 1e6; xy = rand(N, 2); inside = sum(xy(:,1).^2 + xy(:,2).^2 <= 1); pi_est = 4 * inside / N; printf("Monte Carlo π (%d samples): %.6f (error: %.2e)\n", N, pi_est, abs(pi_est-pi)); % --- Gaussian integral ∫exp(-x²)dx from -∞ to ∞ = √π --- % Using importance sampling with N(0,1) proposal x = randn(N, 1); % samples from N(0,1) % f(x)/g(x) where g is N(0,1) PDF and f = exp(-x²) w = exp(-x.^2) ./ ((1/sqrt(2*pi))*exp(-x.^2/2)); I_est = mean(w); printf("∫exp(-x²)dx ≈ %.6f (exact √π = %.6f)\n", I_est, sqrt(pi));
13.7 — Numerical PDE: Heat Equation
% u_t = α·u_xx on [0,1], u(0,t)=u(1,t)=0, u(x,0)=sin(πx) alpha = 0.01; Nx = 50; dx = 1/Nx; dt = 0.4*dx^2/alpha; % stability: dt ≤ dx²/(2α) Nt = round(1.0/dt); x = (1:Nx-1)'*dx; u = sin(pi*x); r = alpha*dt/dx^2; for n = 1:Nt u_new = u; u_new(2:end-1) = u(2:end-1) + r*(u(3:end) - 2*u(2:end-1) + u(1:end-2)); u_new(1) = u(1) + r*(u(2) - 2*u(1)); u_new(end) = u(end) + r*(-2*u(end) + u(end-1)); u = u_new; end u_exact = exp(-alpha*pi^2*Nt*dt) * sin(pi*x); printf("Heat eq at t=%.2f: max error = %.3e (CFL ratio r=%.3f)\n", Nt*dt, max(abs(u-u_exact)), r);
13.8 — Hilbert Transform & Analytic Signal
% Hilbert transform via FFT: H{f}(t) = (1/π) PV∫ f(τ)/(t-τ) dτ N = 1024; t = linspace(0, 1, N); sig = sin(2*pi*5*t) + 0.5*sin(2*pi*12*t); F = fft(sig); h = zeros(1, N); h(1) = 1; h(2:floor(N/2)) = 2; h(floor(N/2)+1) = 1; analytic = ifft(F .* h); envelope = abs(analytic); inst_freq = diff(unwrap(angle(analytic))) / (2*pi*(t(2)-t(1))); printf("Analytic signal: envelope range [%.3f, %.3f]\n", min(envelope), max(envelope)); printf("Instantaneous freq range: [%.1f, %.1f] Hz\n", min(inst_freq), max(inst_freq));
13.9 — Bessel Functions & Fresnel Integrals
% Bessel J₀(x) = (1/π)∫₀^π cos(x sin θ) dθ function val = bessel_j0_quad(x) val = quad(@(th) cos(x*sin(th)), 0, pi) / pi; end x_test = [0, 1, 2.4048, 5, 10]; % 2.4048 is first zero of J₀ printf("Bessel J₀ via quadrature:\n"); for xv = x_test printf(" J₀(%.4f) = %10.7f (builtin: %10.7f)\n", xv, bessel_j0_quad(xv), besselj(0,xv)); end % Fresnel integrals: C(x)=∫₀ˣ cos(πt²/2)dt, S(x)=∫₀ˣ sin(πt²/2)dt function [C, S] = fresnel(x) C = quad(@(t) cos(pi*t.^2/2), 0, x); S = quad(@(t) sin(pi*t.^2/2), 0, x); end [C5,S5] = fresnel(5); printf("Fresnel at x=5: C=%.6f, S=%.6f (both → 0.5 as x→∞)\n", C5, S5);
13.10 — Symbolic-Numeric Verification
% Comprehensive verification of calculus identities printf("=== CALCULUS IDENTITY VERIFICATION ===\n\n"); % 1. FTC: ∫₀^π sin(x)dx = [-cos(x)]₀^π = 2 I1 = quad(@sin, 0, pi); printf("FTC: ∫₀^π sin(x)dx = %.10f (exact 2)\n", I1); % 2. Euler: e^(iπ) + 1 = 0 euler = exp(1i*pi) + 1; printf("Euler: |e^(iπ)+1| = %.2e\n", abs(euler)); % 3. Gaussian: ∫exp(-x²)dx = √π I3 = quad(@(x)exp(-x.^2), -20, 20); printf("Gaussian: ∫exp(-x²) = %.10f (exact √π=%.10f)\n", I3, sqrt(pi)); % 4. Basel: Σ1/n² = π²/6 n = 1:1e6; basel = sum(1./n.^2); printf("Basel: Σ1/n² = %.10f (exact π²/6=%.10f)\n", basel, pi^2/6); % 5. Leibniz: π/4 = 1 - 1/3 + 1/5 - 1/7 + ... n = 0:1e6; leibniz = sum((-1).^n ./ (2*n+1)); printf("Leibniz: series = %.10f (exact π/4=%.10f)\n", leibniz, pi/4); % 6. Stirling: n! ≈ √(2πn)(n/e)^n n = 20; stirling = sqrt(2*pi*n) * (n/exp(1))^n; printf("Stirling: 20! = %.4e, approx = %.4e, ratio = %.8f\n", factorial(n), stirling, factorial(n)/stirling); % 7. Residue: ∫₀^∞ 1/(1+x²) = π/2 I7 = quad(@(x) 1./(1+x.^2), 0, 1000); printf("Residue check: ∫₀^∞ 1/(1+x²) = %.10f (exact π/2=%.10f)\n", I7, pi/2); % 8. Machin's formula: π/4 = 4·arctan(1/5) - arctan(1/239) machin = 4*4*atan(1/5) - 4*atan(1/239); printf("Machin: 4(4·atan(1/5)-atan(1/239)) = %.15f\n π = %.15f\n", machin, pi);
⚡ Quick Reference Card
Derivative Rules
| Rule | Formula |
|---|---|
| Power | d/dx [xⁿ] = nxⁿ⁻¹ |
| Product | (fg)′ = f′g + fg′ |
| Quotient | (f/g)′ = (f′g − fg′)/g² |
| Chain | d/dx [f(g(x))] = f′(g(x))·g′(x) |
| Exponential | d/dx [eˣ] = eˣ | d/dx [aˣ] = aˣ ln a |
| Logarithm | d/dx [ln x] = 1/x | d/dx [loga x] = 1/(x ln a) |
Trig Derivatives
| f(x) | f′(x) | f(x) | f′(x) |
|---|---|---|---|
| sin x | cos x | arcsin x | 1/√(1−x²) |
| cos x | −sin x | arccos x | −1/√(1−x²) |
| tan x | sec² x | arctan x | 1/(1+x²) |
| csc x | −csc x cot x | arcsec x | 1/(|x|√(x²−1)) |
| sec x | sec x tan x | arccsc x | −1/(|x|√(x²−1)) |
| cot x | −csc² x | arccot x | −1/(1+x²) |
Essential Integrals
| ∫ f(x) dx | Result + C |
|---|---|
| ∫ xⁿ dx | xⁿ⁺¹/(n+1) (n≠−1) |
| ∫ 1/x dx | ln|x| |
| ∫ eˣ dx | eˣ |
| ∫ sin x dx | −cos x |
| ∫ cos x dx | sin x |
| ∫ sec² x dx | tan x |
| ∫ sec x tan x dx | sec x |
| ∫ 1/(1+x²) dx | arctan x |
| ∫ 1/√(1−x²) dx | arcsin x |
| ∫ tan x dx | −ln|cos x| |
| ∫ sec x dx | ln|sec x + tan x| |
Key Series
| Function | Maclaurin Series | Radius |
|---|---|---|
| eˣ | Σ xⁿ/n! | ∞ |
| sin x | Σ (−1)ⁿ x²ⁿ⁺¹/(2n+1)! | ∞ |
| cos x | Σ (−1)ⁿ x²ⁿ/(2n)! | ∞ |
| 1/(1−x) | Σ xⁿ | 1 |
| ln(1+x) | Σ (−1)ⁿ⁺¹ xⁿ/n | 1 |
| arctan x | Σ (−1)ⁿ x²ⁿ⁺¹/(2n+1) | 1 |
Fundamental Theorems
| Theorem | Statement |
|---|---|
| FTC Part 1 | d/dx ∫ₐˣ f(t)dt = f(x) |
| FTC Part 2 | ∫ₐᵇ f(x)dx = F(b)−F(a) where F′=f |
| MVT | ∃c∈(a,b): f′(c) = [f(b)−f(a)]/(b−a) |
| Taylor | f(x) = Σ f⁽ⁿ⁾(a)(x−a)ⁿ/n! |
| Green's | ∮ P dx+Q dy = ∬ (∂Q/∂x−∂P/∂y) dA |
| Stokes' | ∮ F·dr = ∬ (∇×F)·dS |
| Divergence | ∯ F·dS = ∭ ∇·F dV |
| Cauchy | f(a) = (1/2πi) ∮ f(z)/(z−a) dz |
| Residue | ∮ f dz = 2πi Σ Res(f, zₖ) |