Lesson 5 of 18

Partial Derivative ∂f/∂x

Partial Derivatives

A function of two variables, f(x,y)f(x, y), has two partial derivatives — one for each variable.

f/x\partial f / \partial x

The partial derivative with respect to xx treats yy as a constant and differentiates normally:

fx=limh0f(x+h,y)f(xh,y)2h\frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h,\, y) - f(x-h,\, y)}{2h}

This is the central difference approximation — more accurate than a one-sided difference.

Intuition

  • f/x\partial f / \partial x measures the rate of change of ff as you move in the xx-direction
  • Think of it as the slope of ff along the xx-axis, holding yy frozen

Examples

For f(x,y)=x2+y2f(x, y) = x^2 + y^2:

  • f/x=2x\partial f / \partial x = 2x (treat y2y^2 as constant → derivative is 0)

For f(x,y)=xyf(x, y) = x \cdot y:

  • f/x=y\partial f / \partial x = y (treat yy as a constant multiplier)

For f(x,y)=x3+2xyf(x, y) = x^3 + 2xy:

  • f/x=3x2+2y\partial f / \partial x = 3x^2 + 2y

Your Task

Implement double partial_x(double (*f)(double, double), double x, double y, double h) that approximates f/x\partial f / \partial x at (x,y)(x, y) using step size hh.

TCC compiler loading...
Loading...
Click "Run" to execute your code.