Tutorial 1
Click the badges above to run this tutorial interactively in your browser without installing anything!
- Binder: Free cloud-based Jupyter environment
- Colab: Google's free Jupyter notebook environment
Topics Covered
This tutorial covers the following topics using Python and SymPy:
- Limits: Computing limits using limit definition
- Derivatives: First derivatives using differentiation rules
- Implicit Differentiation: Finding derivatives of implicitly defined functions
- Parametric Equations: Derivatives of parametric curves
Introduction
Sympy: SymPy is a Python library for symbolic mathematics. We will use this library to solve all the tutorials.
import sympy as sy
from sympy.abc import x, y, t # variable x
from sympy.solvers import solve # Solving equations
from sympy import sqrt,tan,sin,cos,sec,pi,root,ln
from sympy import log,exp,atan,asinh,atanh,asin # Import all required math function
from sympy import diff, idiff # Solving differentiation
sy.init_printing(use_latex=True) # Show it in natural display
How to use sympy to solve limit questions?
Declare the symbol to be used in the function. For example, if you wanted to use the symbol , just use x as usual because we have import the variable x earlier. Alternatively, you can declare such that
x = sy.symbols('x'). This will make the variablexa representation of in the function to be solved. Note thatsyis used because weimport sympy as sy.Type the function. For example, if the function is , type it as
1/x. Note, for power, python uses**instead of^.Solve the limit with
sympylibrary by usingsy.limit(function,symbol,limit).sy.limittakes three parameters, which are the function, the symbols used in the function and the limit. The return of this fuction will be the answer.
How to use sympy to solve derivative questions?
Just diff(function,symbol)!
Some cheat sheet!
To make sure if you input the equation correctly, you can use the display(function) function. For example,
x = sqrt(x)
display(x)
will return:
The representation of mathematics function in Python:
| Mathematics Function | Python representation |
|---|---|
x**2 | |
sqrt(x) | |
root(x,3) | |
tan(x) | |
sec(x) | |
pi |
Note that the sqrt, tan, sec, pi used in this notebook are from sympy library, not from math library.
That's it! Let's use this knowledge and solve them.
Question 1
Use the limit definition to evaluate:
a.
lim = 5
func = (x**2-25)/(x**2+x-30)
sy.limit(func,x,lim)
b.
lim = 9
func = (sqrt(x)-3)/(x-9)
sy.limit(func,x,lim)
c.
lim = 0
func = x/(3-sqrt(x+9))
sy.limit(func,x,lim)
Question 2
Find the derivative of
diff(log(4+cos(x),10))
Question 3
Find for
eqn=cos(x**2)-x*exp(y)
idiff(eqn,y,x)
Question 4
Find for
eqn=x**3*y**3-2*y-x
idiff(eqn,y,x)
Question 5
A curve in the plane is defined parametrically by the equations and . Find
dydt = sqrt(1-4*t).diff(t)
dxdt = 7*ln(t).diff(t)
dydt/dxdt
Question 6
A curve in the plane is defined parametrically by the equations and . Find
dydt = 2*exp(t).diff(t)
dxdt = (t**2-1).diff(t)
dydt/dxdt
Question 7
Find for each of the following:
a.
eqn=x**2*tan(y)+y**10*sec(x)-2*x
idiff(eqn,y,x)
b.
eqn=x**3*y**5+3*x-8*y**3-1
idiff(eqn,y,x)
c.
eqn=exp(2*x+3*y)-x**2+ln(x*y**3)
idiff(eqn,y,x)
Question 8
Solve for if
diff(ln(cos(x**2)))
Question 9
Find for
eqn=10*exp(2*x*y)-exp(15*y)-exp(13*x)
idiff(eqn,y,x)
Question 10
Solve if
diff(2*x*(atan(5*x))**2+6*tan(cos(6*x)))
Question 11
Solve if
diff(4*x*asinh(x/6)+atanh(cos(10*x)))
Extra Learning Resources
Key Concepts to Master
- Limit Laws: Sum, product, quotient rules for limits
- Differentiation Rules: Power rule, product rule, quotient rule, chain rule
- Trigonometric Derivatives: Derivatives of sin, cos, tan, sec, etc.
- Implicit Differentiation: Finding derivatives without solving for y explicitly
- Parametric Derivatives: Using
SymPy Resources
- SymPy Calculus Tutorial - Official tutorial on limits and derivatives
- SymPy Limits Documentation - Detailed limit computation methods
- SymPy Differentiation Guide - Complete guide to derivatives in SymPy
Practice Problems
- Try solving the same problems using different methods (e.g., algebraic simplification before limits)
- Experiment with
display()function to verify your input expressions - Use
simplify()to clean up complex derivative expressions - Practice with one-sided limits using
limit(f, x, a, '+')orlimit(f, x, a, '-')
Common Pitfalls
- Remember to use
**for exponents, not^ - Import necessary functions from SymPy (sin, cos, log, etc.)
- For implicit differentiation, use
idiff(equation, y, x)notdiff() - Logarithm base:
log(x, base)- e.g.,log(x, 10)for log₁₀(x)