Python Encyclopedia for Academics
  • Course Outline
  • Artificial Intelligence
    • Data Science Foundation
      • Python Programming
        • Introduction and Basics
          • Variables
          • Print Function
          • Input From User
          • Data Types
          • Type Conversion
        • Operators
          • Arithmetic Operators
          • Relational Operators
          • Bitwise Operators
          • Logical Operators
          • Assignment Operators
          • Compound Operators
          • Membership Operators
          • Identity Operators
      • Numpy
        • Vectors, Matrix
        • Operations on Matrix
        • Mean, Variance, and Standard Deviation
        • Reshaping Arrays
        • Transpose and Determinant of Matrix
      • Pandas
        • Series and DataFrames
        • Slicing, Rows, and Columns
        • Operations on DataFrames
        • Different wayes to creat DataFrame
        • Read, Write Operations with CSV files
      • Matplotlib
        • Graph Basics
        • Format Strings in Plots
        • Label Parameters, Legend
        • Bar Chart, Pie Chart, Histogram, and Scatter Plot
  • Machine Learning Algorithms
    • Regression Analysis In ML
      • Regression Analysis in Machine Learning
      • Proof of Linear Regression Formulas
      • Simple Linear Regression Implementation
      • Multiple Linear Regression
      • Advertising Dataset Example
      • Bike Sharing Dataset
      • Wine Quality Dataset
      • Auto MPG Dataset
    • Classification Algorithms in ML
      • Proof of Logistic Regression
      • Simplified Mathematical Proof of SVM
      • Iris Dataset
  • Machine Learning Laboratory
    • Lab 1: Titanic Dataset
      • Predicting Survival on the Titanic with Machine Learning
    • Lab 2: Dow Jones Index Dataset
      • Dow Jones Index Predictions Using Machine Learning
    • Lab 3: Diabetes Dataset
      • Numpy
      • Pandas
      • Matplotlib
      • Simple Linear Regression
      • Simple Non-linear Regression
      • Performance Matrix
      • Preprocessing
      • Naive Bayes Classification
      • K-Nearest Neighbors (KNN) Classification
      • Decision Tree & Random Forest
      • SVM Classifier
      • Logistic Regression
      • Artificial Neural Network
      • K means Clustering
    • Lab 4: MAGIC Gamma Telescope Dataset
      • Classification in ML-MAGIC Gamma Telescope Dataset
    • Lab 5: Seoul Bike Sharing Demand Dataset
      • Regression in ML-Seoul Bike Sharing Demand Dataset
    • Lab 6: Medical Cost Personal Datasets
      • Predict Insurance Costs with Linear Regression in Python
    • Lab 6: Predict The S&P 500 Index With Machine Learning And Python
      • Predict The S&P 500 Index With Machine Learning And Python
  • Artificial Neural Networks
    • Biological Inspiration vs. Artificial Neurons
    • Review linear algebra and calculus essentials for ANNs
    • Activation Function
  • Mathematics
    • Pre-Calculus
      • Factorials
      • Roots of Polynomials
      • Complex Numbers
      • Polar Coordinates
      • Graph of a Function
    • Calculus 1
      • Limit of a Function
      • Derivative of Function
      • Critical Points
      • Indefinite Integrals
  • Calculus 2
    • 3D Coordinates and Vectors
    • Vectors and Vector Operations
    • Lines and Planes in Space (3D)
    • Partial Derivatives
    • Optimization Problems (Maxima/Minima) in Multivariable Functions
    • Gradient Vectors
  • Engineering Mathematics
    • Laplace Transform
  • Electrical & electronics Eng
    • Resistor
      • Series Resistors
      • Parallel Resistors
    • Nodal Analysis
      • Example 1
      • Example 2
    • Transient State
      • RC Circuit Equations in the s-Domain
      • RL Circuit Equations in the s-Domain
      • LC Circuit Equations in the s-Domain
      • Series RLC Circuit with DC Source
  • Computer Networking
    • Fundamental
      • IPv4 Addressing
      • Network Diagnostics
  • Cybersecurity
    • Classical Ciphers
      • Caesar Cipher
      • Affine Cipher
      • Atbash Cipher
      • Vigenère Cipher
      • Gronsfeld Cipher
      • Alberti Cipher
      • Hill Cipher
Powered by GitBook
On this page
  • What Are Partial Derivatives?
  • Step-by-Step: How to Calculate
  • Geometric Meaning
  • Visualizing Partial Derivatives in Python
  • Practice Problem
  • Keywords
  1. Calculus 2

Partial Derivatives

Nerd Cafe

PreviousLines and Planes in Space (3D)NextOptimization Problems (Maxima/Minima) in Multivariable Functions

Last updated 1 month ago

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+3xy2f(x,y)=x^{2}y+3xy^{2}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+3xy2f(x,y)=x^{2}y+3xy^{2}f(x,y)=x2y+3xy2

Step 1: Partial Derivative with Respect to x

  • y is constant

  • Differentiate:

Step 2: Partial Derivative with Respect to y

  • x is constant

  • Differentiate:

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

∂f∂x=∂∂x(x2y+3xy2)=2xy+3y2\frac{\partial f}{\partial x}=\frac{\partial }{\partial x}\left( x^{2}y+3xy^{2} \right)=2xy+3y^{2}∂x∂f​=∂x∂​(x2y+3xy2)=2xy+3y2
∂f∂y=∂∂y(x2y+3xy2)=x2+6xy\frac{\partial f}{\partial y}=\frac{\partial }{\partial y}\left( x^{2}y+3xy^{2} \right)=x^{2}+6xy∂y∂f​=∂y∂​(x2y+3xy2)=x2+6xy
f(x,y,z)=x2y+y2z+z2xf(x,y,z)=x^{2}y+y^{2}z+z^{2}xf(x,y,z)=x2y+y2z+z2x
∂f∂x  ,  ∂f∂y  ,  ∂f∂z\frac{\partial f}{\partial x} \; , \; \frac{\partial f}{\partial y} \; , \; \frac{\partial f}{\partial z}∂x∂f​,∂y∂f​,∂z∂f​