Calculus I

Lecture 20

Dr. Greg Chism

University of Arizona
INFO 511 - Spring 2025

Calculus in data science

  • Optimization Algorithms: Calculus is essential for understanding and implementing optimization algorithms like gradient descent, which are used to minimize error functions in machine learning models.

  • Modeling Change: Derivatives help in modeling and understanding the rate of change in various phenomena, which is crucial for predictive analytics and dynamic systems in data science.

  • Integral Applications: Integrals are used in calculating areas under curves, which is fundamental for probability distributions, statistical inference, and understanding cumulative effects in data analysis.

Functions and their graphs

  • Definition
  • Examples
  • Plotting
  • Code
  • A function is a relation between a set of inputs and a set of permissible outputs, where each input is related to exactly one output.

  • Mathematical notation: f(x) denotes a function named f with x as the input variable.

  • Linear function: f(x)=2x+3

  • Quadratic function: f(x)=x2−4x+4

  • Exponential function: f(x)=ex

  • Logarithmic function: f(x)=log(x)

Using matplotlib

Using SymPy

Using matplotlib

import matplotlib.pyplot as plt
import numpy as np

# Define the function
def f(x):
    return 2 * x + 3

# Generate x values
x = np.linspace(-10, 10, 400)
y = f(x)

# Plot the function
plt.plot(x, y, label='f(x) = 2x + 3')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('Graph of the Linear Function')
plt.legend()
plt.grid(True)
plt.show()

Using SymPy

from sympy import symbols, plot

# Define the variable and function
x = symbols('x')
f = 2 * x + 3

# Plot the function
plot(f)

Importance of functions in modeling

  • Predictive Modeling:

    • Functions predict outputs from inputs, essential for machine learning.

    • Example: Linear regression predicts continuous outcomes.

  • Descriptive Analysis:

    • Functions describe relationships, revealing patterns and trends.

    • Example: Growth functions model population or business growth.

  • Decision Making:

    • Functions formulate decision rules and optimization problems.

    • Example: Cost functions minimize expenses or maximize profits.

Overview of Calculus

Branch of mathematics that studies continuous change.

Differential (rates of change & slopes of curves)

Integral (accumulation of quantities & areas under curves)

Differentiation and Integration

  • Differentiation
  • Integration
  • Measures the rate at which a quantity changes.

  • Example: In machine learning, the derivative of the loss function with respect to model parameters helps in finding the optimal parameters.

  • Symbol: dydx of f′(x)

  • Practical Application: Gradient Descent Algorithm

  • Measures the accumulation of quantities and the area under a curve.

  • Example: Used to compute the area under probability distribution functions, which is essential in statistics and data analysis.

  • Symbol: ∫f(x)dx

  • Practical Application: Calculating Cumulative Distribution Functions (CDFs)

Derivatives

Calculating the slope

slope=riserun

slope=change in distance(Δx)change in time(Δt)

slope=x(15)−x(10)t(15)−t(10)

slope=202m−122m15s−10s

slope=80m5s=16m/s

The derivative

The derivative

The derivative

The derivative

The derivative

The derivative

Derivatives in Python

Calculating derivatives using SymPy

from sympy import symbols, diff

x = symbols('x')
f = x**2 # x^2
df = diff(f)
print(df)
2*x

Solving derivatives

Differentiation rules

  • Constant rule: ddx(c)=0

  • Power rule: ddx(xn)=nxn−1

  • Constant multiple rule: ddx[c⋅f(x)]=c⋅f′(x)

  • Sum rule: ddx[f(x)+g(x)]=f′(x)+g′(x)

  • Difference rule: ddx[f(x)−g(x)]=f′(x)−g′(x)

Example 1: Differentiating a Constant

  • Function: f(x)=7

  • Derivative: f′(x)=0

Example 2: Power rule

  • Function: f(x)=x3

  • Derivative: f′(x)=ddx(x3)=3x2

Example 3: Constant multiple rule

  • Function: f(x)=5x2

  • Derivative: f′(x)=5⋅ddx(x2)=5⋅2x=10x

Example 4: Sum and difference rule

  • Function: f(x)=x3+4x−5

  • Derivative: f′(x)=ddx(x3)+ddx(4x)−ddx(5)=3x2+4−0=3x2+4

Solving complex derivatives

Complex Derivatives:

  • Involves functions composed of multiple less complex functions.

  • Requires application of rules like the chain rule and product rule for differentiation.

Example Function: h(x)=(ln(x)⋅eax)k

  • Objective: Find the derivative ddxh(x)

The Chain Rule

(f(g(x)))′=f′(g(x))⋅g′(x)

  • Used when differentiating a composition of functions

The Chain Rule: Composition

Function: f(x)=(3x2+2)5

  1. Identify the Outer and Inner Functions
  • Outer function: u5

  • Inner function: u=3x2+2

  1. Apply the Chain Rule

f′(x)=5(3x2+2)4⋅ddx(3x2+2)

The Chain Rule: Composition

Function: f(x)=(3x2+2)5

  1. Differentiate the Inner Function

ddx(3x2+2)=6x

  1. Combine the results

f′(x)=5(3x2+2)4⋅6x

f′(x)=30x(3x2+2)4

The Chain Rule: Nested composition

Function: g(x)=sin(x3+4x)

  1. Identify the Outer and Inner Functions
  • Outer function: sin(u)

  • Inner function: u=x3+4x

  1. Apply the Chain Rule

g′(x)=cos(x3+4x)⋅ddx(x3+4x)

The Chain Rule: Nested composition

Function: g(x)=sin(x3+4x)

  1. Differentiate the Inner Function

ddx(x3+4x)=3x2+4

  1. Combine the Results

g′(x)=cos(x3+4x)⋅(3x2+4)

The Chain Rule: Complex nested composition

Function: h(x)=(ex2⋅ln(x))2

  1. Identify the Outer and Inner Functions
  • Outer function: u2

  • Inner function: u=ex2⋅ln(x)

  1. Apply the Chain Rule

h′(x)=2(ex2⋅ln(x))⋅ddx(ex2⋅ln(x))

The Chain Rule: Complex nested composition

Function: h(x)=(ex2⋅ln(x))2

  1. Differentiate the Inner Function using the Product Rule
  • Inner function: u=ex2⋅ln(x)

  • Product rule: (u⋅v)′=u′⋅v+u⋅v′

  • Let u=ex2 and v=ln(x)

  • u′=ddx(ex2)=2xex2

  • v′=ddx(ln(x))=1x

The Chain Rule: Complex nested composition

Function: h(x)=(ex2⋅ln(x))2

  1. Combine the Produce Rule Results
  • ddx(ex2⋅ln(x))=(2xex2)⋅ln(x)+ex2⋅1x

  • =2xex2ln(x)+ex2x

The Chain Rule: Complex nested composition

Function: h(x)=(ex2⋅ln(x))2

  1. Combine with the Outer Function Derivative
  • h′(x)=2(ex2⋅ln(x))⋅(2xex2ln(x)+ex2x)

  • Simplify:

  • h′(x)=2ex2ln(x)(2xex2ln(x)+ex2x)

  • h′(x)=2ex2ln(x)(2xex2ln(x)+ex2⋅x−1)

Partial derivatives

Partial derivatives

Definition:

  • A partial derivative represents the rate of change of a function with respect to one variable while keeping other variables constant.

  • Notation: ∂f∂x denotes the partial derivative of f with respect to x.

Partial derivatives

Significance:

  • Essential in understanding functions of multiple variables.

  • Crucial for optimization in multivariable calculus.

  • Used in various fields such as physics, engineering, and economics to model complex systems.

Application in multi-variable functions

Multi-variable functions:

  • Functions that depend on two or more variables, e.g., f(x,y)=x2+y2

Gradient:

  • The vector of all partial derivatives in a function.

  • Indicates the direction of the steepest ascent

  • Notation: ∇f=(∂f∂x,∂f∂y)

Partial derivatives in Python

Given the function f(x,y)=x3+3xy+y3, calculate the partial derivatives with respect to x and y:

from sympy import symbols, diff

# Define the variables and function
x, y = symbols('x y')
f = x**3 + 3*x*y + y**3

# Calculate partial derivatives
partial_x = diff(f, x)
partial_y = diff(f, y)

print(partial_x)  # Output: 3*x**2 + 3*y
print(partial_y)  # Output: 3*x + 3*y**2
3*x**2 + 3*y
3*x + 3*y**2

Gradient descent

You’ll learn more about this in INFO 521: Introduction to Machine Learning

ae-13-derivation

Derivations (you will be tested on this in Exam 2)

🔗 datasciaz.netlify.app

1 / 38
Calculus I Lecture 20 Dr. Greg Chism University of Arizona INFO 511 - Spring 2025

  1. Slides

  2. Tools

  3. Close
  • Calculus I
  • Slide 2
  • Calculus in data science
  • Functions and their graphs
  • Importance of functions in modeling
  • Overview of Calculus
  • Differentiation and Integration
  • Derivatives
  • Calculating the slope
  • The derivative
  • The derivative
  • The derivative
  • The derivative
  • The derivative
  • The derivative
  • Derivatives in Python
  • Solving derivatives
  • Example 1: Differentiating a Constant
  • Example 2: Power rule
  • Example 3: Constant multiple rule
  • Example 4: Sum and difference rule
  • Solving complex derivatives
  • The Chain Rule
  • The Chain Rule: Composition
  • The Chain Rule: Composition
  • The Chain Rule: Nested composition
  • The Chain Rule: Nested composition
  • The Chain Rule: Complex nested composition
  • The Chain Rule: Complex nested composition
  • The Chain Rule: Complex nested composition
  • The Chain Rule: Complex nested composition
  • Partial derivatives
  • Partial derivatives
  • Partial derivatives
  • Application in multi-variable functions
  • Partial derivatives in Python
  • Gradient descent
  • ae-13-derivation
  • f Fullscreen
  • s Speaker View
  • o Slide Overview
  • e PDF Export Mode
  • b Toggle Chalkboard
  • c Toggle Notes Canvas
  • d Download Drawings
  • ? Keyboard Help