Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Calculus in Python with SymPy – Limits, Derivatives, and Integration

  • Siddhi SawantSiddhi Sawant
  • January 27, 2021
  • Python Programming Examples
Calculus in Python with SymPy – Limits, Derivatives, and Integration

Let’s learn to perform Calculus in Python. Calculus is a part of mathematics. It was discovered by Isaac Newton and Gottfried. In a nutshell, is an answer to two big questions related to functions.

  • The First Question: At a particular point, how steep is a function? The solution to this question can be obtained by using Derivatives. At a particular point, it measures the rate of change of a function.
  • The Second Question: What is the area under the graph over some region? The solution to this question can be obtained by using Integration. It combines the values of the function over a range of numbers.

Using the SymPy Module to Perform Calculus in Python

SymPy in Python Programming stands for Symbolic Python. It is a python library for symbolic mathematics. It does not require any external libraries. For executing python programs for calculus we need to import the module SymPy. SymPy is a module that allows us to interact with mathematical objects in a symbolic way.

To install SymPy module on your Windows System, follow the following Steps :

  • Open your windows/Linux terminal
  • We’ll use the pip package manager to install Sympy. Type pip3 install sympy.
  • Hit enter and your SymPy module will start downloading.
C:\Users\Admin> pip3 install sympy

Topics Covered

  • Limits
  • Derivatives/Differentiation
  • Integration

Calculating Limits in Python

Limits in calculus are used to define continuity, derivatives, and integrals of a function sequence. To calculate limits in Python we use the following syntax:

sympy.limit(function,variable,value)

Now, take for example a limit function as mentioned below:

limit = f(y)
y-->a

In the above-mentioned syntax for calculating the limit in Python the parameters mentioned are function, variable, and value.

  • f(y) is the function on with the limit operation will be performed.
  • y is the variable of the function.
  • a is the value which the limit tends to.

Equation example 1: limit x–>0= sin(x) / x

>>> import sympy as sp
>>> x=sp.Symbol('x')
>>> f=sp.sin(x)/x
>>> L=sp.limit(f,x,0)
>>> print("The Limit is:",L)
The Limit is: 1

Equation example 2 : limit y–>0 = sin(2y) / y

>>> import sympy as sp
>>> y=sp.Symbol('y')
>>> f=sp.sin(2*y)/y
>>> L=sp.limit(f,y,0)
>>> print("The limit is:",L)
The limit is: 2

Calculating Derivatives in Python

A major part of performing calculus in Python is derivatives. For differentiation or finding out the derivatives in limits, we use the following syntax:

sympy.diff(function,variable)

Equation Example 1 : f(x) = sin(x) + x2 + e4x

>>> import sympy as sp
>>> x=sp.Symbol('x')
>>> f=sp.sin(x)+x**2+sp.exp(4*x)
>>> print(f)
x**2 + exp(4*x) + sin(x)
>>> df=sp.diff(f,x)
>>> print(df)
2*x + 4*exp(4*x) + cos(x)
>>> ddf=sp.diff(f,x,2)
>>> print(ddf)
16*exp(4*x) - sin(x) + 2

Equation Example 2 : f(y) = cos(y) + 4y + y3

>>> import sympy as sp
>>> y=sp.Symbol('y')
>>> f=sp.cos(y)+4*y+y**3
>>> print(f)
y**3 + 4*y + cos(y)
>>> df=sp.diff(f,y)
>>> print(df)
3*y**2 - sin(y) + 4

Calculating Integration in Python

The SymPy module in Integration consists of integral modules. The syntax for calculating Integration in python is as followed:

integrate(function,value)

Equation Example 1: y3 + y + 4

>>> from sympy import*
>>> x,y=symbols('x y')
>>> exp=y**3+y+4
>>> integrate(exp,y)
y**4/4 + y**2/2 + 4*y

Equation Example 2: x2 + 4x + 12

>>> from sympy import*
>>> x=symbols('x')
>>> exp= x**2 + 4*x + 12
>>> integrate(exp,x)
x**3/3 + 2*x**2 + 12*x

Conclusion

This brings us to the end of our brief tutorial on performing calculus in Python with the Sympy module. You can learn in detail about the Sympy module in its official documentation.

Siddhi Sawant
Siddhi Sawant
Articles: 14
Diagram Architecture using the diagrams module in Python
Previous Post Diagram Architecture using the diagrams module in Python
Next Post Lasso Regression in Python
Lasso Regression in Python

Related Posts

How to Calculate Distance Between Two Points in Python

How to Calculate Distance Between Two Points in Python

  • November 26, 2026
CIFAR 10 Dataset: Load and Use in Python

CIFAR 10 Dataset: Load and Use in Python

  • November 24, 2026
Maximum A Posteriori Estimation in Python

Maximum A Posteriori Estimation in Python

  • November 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.