Skip to main content

Tutorial 1

Binder Open In Colab

Interactive Notebooks

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?

  1. Declare the symbol to be used in the function. For example, if you wanted to use the symbol xx, just use x as usual because we have import the variable x earlier. Alternatively, you can declare xx such that x = sy.symbols('x'). This will make the variable x a representation of xx in the function to be solved. Note that sy is used because we import sympy as sy.

  2. Type the function. For example, if the function is 1x\frac{1}{x}, type it as 1/x. Note, for power, python uses ** instead of ^.

  3. Solve the limit with sympy library by using sy.limit(function,symbol,limit). sy.limit takes 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:

x\sqrt{x}

The representation of mathematics function in Python:

Mathematics FunctionPython representation
x2x^2x**2
x\sqrt{x}sqrt(x)
x3\sqrt[3]{x}root(x,3)
tanx\tan{x}tan(x)
secx\sec{x}sec(x)
π\pipi

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. limx5x225x2+x30\lim\limits_{x \to 5} \frac{x^2 - 25}{x^2 + x - 30}

lim = 5
func = (x**2-25)/(x**2+x-30)
sy.limit(func,x,lim)

b. limx9x3x9\lim\limits_{x \to 9} \frac{\sqrt{x} - 3}{x - 9}

lim = 9
func = (sqrt(x)-3)/(x-9)
sy.limit(func,x,lim)

c. limx0x3x+9\lim\limits_{x \to 0} \frac{x}{3 - \sqrt{x + 9}}

lim = 0
func = x/(3-sqrt(x+9))
sy.limit(func,x,lim)

Question 2

Find the derivative of log(4+cosx)\log(4+\cos x)

diff(log(4+cos(x),10))

Question 3

Find dydx\frac{dy}{dx} for cos(x2)=xey\cos(x^2)=xe^y

eqn=cos(x**2)-x*exp(y)
idiff(eqn,y,x)

Question 4

Find dydx\frac{dy}{dx} for x3y32y=xx^3y^3-2y=x

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 x=7ln(t)x=7\ln(t) and y=14ty=\sqrt{1-4t}. Find dydx\frac{dy}{dx}

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 x=t21x=t^2-1 and y=2ety=2e^t. Find dydx\frac{dy}{dx}

dydt = 2*exp(t).diff(t)
dxdt = (t**2-1).diff(t)
dydt/dxdt

Question 7

Find yy' for each of the following:

a. x2tan(y)+y10sec(x)=2xx^2\tan(y)+y^{10}\sec(x)=2x

eqn=x**2*tan(y)+y**10*sec(x)-2*x
idiff(eqn,y,x)

b. x3y5+3x=8y3+1x^3y^5+3x=8y^3+1

eqn=x**3*y**5+3*x-8*y**3-1
idiff(eqn,y,x)

c. e2x+3y=x2ln(xy3)e^{2x+3y}=x^2-\ln(xy^3)

eqn=exp(2*x+3*y)-x**2+ln(x*y**3)
idiff(eqn,y,x)

Question 8

Solve for yy' if y=ln(cosx2)y=\ln(\cos x^2)

diff(ln(cos(x**2)))

Question 9

Find yy' for 10e2xy=e15y+e13x10e^{2xy}=e^{15y}+e^{13x}

eqn=10*exp(2*x*y)-exp(15*y)-exp(13*x)
idiff(eqn,y,x)

Question 10

Solve f(x)f'(x) if f(x)=2x(arctan5x)2+6tan(cos6x)f(x)=2x(\arctan 5x)^2+6\tan(\cos 6x)

diff(2*x*(atan(5*x))**2+6*tan(cos(6*x)))

Question 11

Solve yy' if y=4xsinh1(x6)+tanh1(cos10x)y=4x\sinh^{-1}(\frac{x}{6})+\tanh^{-1}(\cos 10x)

diff(4*x*asinh(x/6)+atanh(cos(10*x)))

Extra Learning Resources

Key Concepts to Master

  1. Limit Laws: Sum, product, quotient rules for limits
  2. Differentiation Rules: Power rule, product rule, quotient rule, chain rule
  3. Trigonometric Derivatives: Derivatives of sin, cos, tan, sec, etc.
  4. Implicit Differentiation: Finding derivatives without solving for y explicitly
  5. Parametric Derivatives: Using dydx=dy/dtdx/dt\frac{dy}{dx} = \frac{dy/dt}{dx/dt}

SymPy Resources

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, '+') or limit(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) not diff()
  • Logarithm base: log(x, base) - e.g., log(x, 10) for log₁₀(x)