What Are Partial Derivatives?
A partial derivative is the derivative of a multivariable function with respect to one variable, while keeping the other variables constant.
Example:
Let
f(x,y)=x2y+3xy2 Then:
Partial derivative with respect to x
: treat y
as constant
Partial derivative with respect to y
: treat x
as constant
Step-by-Step: How to Calculate
Let’s calculate the partial derivatives of
f(x,y)=x2y+3xy2 Step 1: Partial Derivative with Respect to x
Step 2: Partial Derivative with Respect to y
Python Code with SymPy
import sympy as sp
# Define symbols
x, y = sp.symbols('x y')
# Define the function
f = x**2 * y + 3 * x * y**2
# Partial derivatives
df_dx = sp.diff(f, x)
df_dy = sp.diff(f, y)
# Show results
print("f(x, y) =", f)
print("∂f/∂x =", df_dx)
print("∂f/∂y =", df_dy)
Output
f(x, y) = x**2*y + 3*x*y**2
∂f/∂x = 2*x*y + 3*y**2
∂f/∂y = x**2 + 6*x*y
Geometric Meaning
For a function f(x,y), the partial derivative ∂f/∂x represents the slope of the surface in the x-direction, holding y constant.
Likewise, ∂f/∂y is the slope in the y-direction.
Visualize it as slicing a 3D surface either along x or along y, and measuring the slope.
Visualizing Partial Derivatives in Python
import numpy as np
import matplotlib.pyplot as plt
# Create grid
x_vals = np.linspace(-3, 3, 50)
y_vals = np.linspace(-3, 3, 50)
X, Y = np.meshgrid(x_vals, y_vals)
# Function and derivatives
Z = X**2 * Y + 3 * X * Y**2
df_dx = 2*X*Y + 3*Y**2
df_dy = X**2 + 6*X*Y
# Plot f(x, y)
fig = plt.figure(figsize=(12, 4))
ax = fig.add_subplot(131, projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis')
ax.set_title('f(x, y)')
# ∂f/∂x
ax = fig.add_subplot(132, projection='3d')
ax.plot_surface(X, Y, df_dx, cmap='plasma')
ax.set_title('∂f/∂x')
# ∂f/∂y
ax = fig.add_subplot(133, projection='3d')
ax.plot_surface(X, Y, df_dy, cmap='coolwarm')
ax.set_title('∂f/∂y')
plt.tight_layout()
plt.show()
Output
Practice Problem
Find:
Solution (with Python)
import numpy as np
import matplotlib.pyplot as plt
# 3-variable function
x, y, z = sp.symbols('x y z')
f = x**2*y + y**2*z + z**2*x
df_dx = sp.diff(f, x)
df_dy = sp.diff(f, y)
df_dz = sp.diff(f, z)
print("∂f/∂x =", df_dx)
print("∂f/∂y =", df_dy)
print("∂f/∂z =", df_dz)
Output
∂f/∂x = 2*x*y + z**2
∂f/∂y = x**2 + 2*y*z
∂f/∂z = 2*x*z + y**2
Keywords
partial derivatives
, multivariable calculus
, symbolic differentiation
, sympy
, python math
, gradient
, calculus
, partial derivative examples
, multivariable functions
, partial derivative python
, ∂f/∂x
, ∂f/∂y
, visualization
, surface plot
, 3D calculus
, partial derivatives visualization
, tangent plane
, mixed partials
, first-order derivatives
, mathematical modeling
, nerd cafe