Intro to Taylor Expansion for Multivariable Functions with examples

What is a Taylor Expansion?

The Taylor expansion is a way to represent a function f(x) (or a multivariable function) as an infinite series based on its derivatives at a specific point a.


Taylor Expansion for Single-Variable Functions

General formula:

f(x) = f(a) + f'(a)(x - a) + \frac{f''(a)}{2!}(x - a)^2 + \frac{f^{(3)}(a)}{3!}(x - a)^3 + \cdots

Or in summation form:

f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!} (x - a)^n

Where:

  • f^{(n)}(a) is the n-th derivative of f(x) at the point a
  • n! is the factorial of n

Taylor Expansion for Multivariable Functions

For a function f(x_1, x_2, \ldots, x_n), the Taylor expansion around the point \mathbf{a} = (a_1, a_2, \ldots, a_n) is written as:

General formula:

f(\mathbf{x}) = f(\mathbf{a}) + \sum_{i=1}^n \frac{\partial f}{\partial x_i}(\mathbf{a})(x_i - a_i) + \frac{1}{2!} \sum_{i=1}^n \sum_{j=1}^n \frac{\partial^2 f}{\partial x_i \partial x_j}(\mathbf{a})(x_i - a_i)(x_j - a_j) + \cdots


Simple example:

For f(x, y), the second-order Taylor expansion at (a, b) is:

f(x, y) = f(a, b) + f_x(a, b)(x - a) + f_y(a, b)(y - b) + \frac{1}{2} \Big[ f_{xx}(a, b)(x - a)^2 + 2f_{xy}(a, b)(x - a)(y - b) + f_{yy}(a, b)(y - b)^2 \Big] + \cdots


Specific Examples

Single-variable function:

Let f(x) = e^x, Taylor expansion around a = 0:

f(x) = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots = \sum_{n=0}^\infty \frac{x^n}{n!}

Two-variable function:

Let f(x, y) = x^2 + xy + y^2, Taylor expansion around (0, 0):

f(x, y) = f(0, 0) + f_x(0, 0)x + f_y(0, 0)y + \frac{1}{2} \Big[ f_{xx}(0, 0)x^2 + 2f_{xy}(0, 0)xy + f_{yy}(0, 0)y^2 \Big]

Calculations:

  • f(0, 0) = 0
  • f_x(0, 0) = 0, f_y(0, 0) = 0
  • f_{xx}(0, 0) = 2, f_{xy}(0, 0) = 1, f_{yy}(0, 0) = 2

Result:

f(x, y) = x^2 + xy + y^2


Python: Taylor Expansion Computation

Using sympy:

import sympy as sp

# Declare variables and function
x, y = sp.symbols('x y')
f = x**2 + x*y + y**2

# Expansion point (0, 0)
a, b = 0, 0

# Taylor expansion to order 2
taylor_expansion = sp.series(f, x=x, y=y, x0=a, y0=b, n=3).removeO()
print("Second-order Taylor expansion:\n", taylor_expansion)

Advanced Examples: Higher-Degree Multivariable Functions

Example 1: f(x, y) = e^x \sin(y), Taylor expansion around (0, 0) up to second order:

Formula:

f(x, y) = f(0, 0) + f_x(0, 0)x + f_y(0, 0)y + \frac{1}{2} \left[ f_{xx}(0, 0)x^2 + 2f_{xy}(0, 0)xy + f_{yy}(0, 0)y^2 \right] + \cdots

Calculations:

  • f(0, 0) = 0
  • f_x(0, 0) = 0, f_y(0, 0) = 1
  • f_{xx}(0, 0) = 0, f_{xy}(0, 0) = 1, f_{yy}(0, 0) = 0

Result:

f(x, y) = y + xy


Example 2: f(x, y, z) = \ln(1 + x + y^2 + z^3), Taylor expansion around (0, 0, 0) to second order.

Formula:

f(x, y, z) = f(0, 0, 0) + \sum_i \frac{\partial f}{\partial x_i}(0) x_i + \frac{1}{2} \sum_{i,j} \frac{\partial^2 f}{\partial x_i \partial x_j}(0) x_i x_j + \cdots

Calculations:

  • f(0, 0, 0) = \ln(1) = 0
  • f_x(0) = 1, f_y(0) = 0, f_z(0) = 0
  • f_{xx}(0) = -1, f_{yy}(0) = 2, f_{zz}(0) = 0

Result:

f(x, y, z) = x - \frac{1}{2}x^2 + y^2


Discover more from Science Comics

Subscribe to get the latest posts sent to your email.

Leave a Reply

error: Content is protected !!