# Python Program for implementation of simpson's rule

# Python Program for implementation of Simpson's rule

In this, program uses Simpson's 1/3 rule to determine the approximate number for combining numbers in the Python programming.

### Simpson's System 1/3 Python Method

In this python system, the lower_limit and upper_limit are the lower and upper limit of a integration, sub_interval is the minimum number used when finding the sum and function f (x) to be combined in the simulation of Simpson 1/3 defined using python.

#### Implementation

For the implementation you have to write a function called simps that takes the input parameters f, a, b and N and returns the approximation. In addition, let us provide the default value of N.

scipy.integrate.simps

#### The SciPy

scipy.integrate subpackage includes many functions for approximation integral and numerically solved different equations.

Let's import the subpackage as name spi.

import scipy.integrate as spi

The scipy.integrate.simps function computes a approximation of a definite integral by the of Simpson rule. scipy.integrate.simps returns approxiamtion of the integral using Simpson's rule.

#### Example 1: Write a program for the implementation of 1/x

**Python code:**

`from scipy.integrate import simps`

import numpy as np

import scipy.integrate as spi

N = 8

a = 1

b = 2

x = np.linspace(a,b,N)

y = 1/x

appoximation = spi.simps(y,x)

print(appoximation)

Output:`0.6933892496392496`

## Example 2: Write a program for the implementation of x2

Python code:`from scipy.integrate import simps`

import numpy as np

import scipy.integrate as spi

N = 8

a = 1

b = 2

x = np.linspace(a,b,N)

y = x**2

appoximation = spi.simps(y,x)

print(appoximation)

Output:`2.3338192419825075`