Are you looking to Make A Numerical Integral Calculator Based On python? Well in this post I am going to cover how to make both. How to make a Definite Integral calculator and Indefinite integral calculator on python language. Excited?
Well, that is enough of the introduction part, I do not want to make it lengthy and boring, so keeping stuck to the point. Let us straightly jump into the post.
What Are We Going To Use?
For building our integral calculator, you need to have 3 things:-
- Python 3 Installed On your computer.
- Basic Knowledge Of maths (If I Say Basic, I mean very less 😛 )
- A maths library called Sympy (Will tell you how to install that further in the article )
So If you have the first 2 things ready, then we are good enough to start building our numerical integration python. Now we have to install the Sympy mathematics library for python on our computer.
To install sympy, just enter pip install sympy, and the sympy library will be installed on your computer.
Before diving into the post, previously I have already written a post on how to make Python Derivative Calculator. You can also check that out.
1- Making Indefinite Integral Calculator On Python
So here is the code of python script to make Indefinite Integral calculator. Just copy and make a new .py file and save it.
from sympy import Symbol, integrate equation = input("Enter Equation : ") x = Symbol('x') result = integrate(equation, x) print(result)
Now after saving your python file. Run it. Now it asks you to enter your integral equation. Just enter Your equation.
Note:- While writing your equation, be sure that for multiplication you have to use “*” symbol. And for raising exponential power, you have to use “**“. For example
x+(4*x) – 36
(4*x) + 23 + (x**3)
If you have any doubt in entering equations, you can comment down. I will help you with that.
Now lets head over to another part, that is calculating definite integral on python.
2- Making Definite Numerical Integration On Python
Now let me tell you how you can also calculate definite Numerical integration on python. Like the previous one, again copy and paste the below script in a new.py file.
from sympy import Symbol, integrate equation = input("Enter Equation : ") lowerlimit = str(input("Enter Lower Limit: ")) upperlimit = str(input("Enter Upper Limit : ")) x = Symbol('x') result = integrate(equation, (x, lowerlimit, upperlimit)) print(result)
After saving the file. Just run it, and it will ask you to enter the equation. As mentioned previously you have to enter the equation in the same manner. After Entering the equation, it will ask you to enter the lower limit and the upper limit of your equation. Then, after entering all the 3 things. It will calculate the answer and then it will show to you.