maths.numerical_analysis.integration_by_simpson_approx

Author : Syed Faizan ( 3rd Year IIIT Pune ) Github : faizan2700

Purpose : You have one function f(x) which takes float integer and returns float you have to integrate the function in limits a to b. The approximation proposed by Thomas Simpson in 1743 is one way to calculate integration.

( read article : https://cp-algorithms.com/num_methods/simpson-integration.html )

simpson_integration() takes function,lower_limit=a,upper_limit=b,precision and returns the integration of function in given limit.

Attributes

N_STEPS

Functions

f(→ float)

simpson_integration(→ float)

Args:

Module Contents

maths.numerical_analysis.integration_by_simpson_approx.f(x: float) float
maths.numerical_analysis.integration_by_simpson_approx.simpson_integration(function, a: float, b: float, precision: int = 4) float
Args:

function : the function which’s integration is desired a : the lower limit of integration b : upper limit of integration precision : precision of the result,error required default is 4

Returns:

result : the value of the approximated integration of function in range a to b

Raises:

AssertionError: function is not callable AssertionError: a is not float or integer AssertionError: function should return float or integer AssertionError: b is not float or integer AssertionError: precision is not positive integer

>>> simpson_integration(lambda x : x*x,1,2,3)
2.333
>>> simpson_integration(lambda x : x*x,'wrong_input',2,3)
Traceback (most recent call last):
    ...
AssertionError: a should be float or integer your input : wrong_input
>>> simpson_integration(lambda x : x*x,1,'wrong_input',3)
Traceback (most recent call last):
    ...
AssertionError: b should be float or integer your input : wrong_input
>>> simpson_integration(lambda x : x*x,1,2,'wrong_input')
Traceback (most recent call last):
    ...
AssertionError: precision should be positive integer your input : wrong_input
>>> simpson_integration('wrong_input',2,3,4)
Traceback (most recent call last):
    ...
AssertionError: the function(object) passed should be callable your input : ...
>>> simpson_integration(lambda x : x*x,3.45,3.2,1)
-2.8
>>> simpson_integration(lambda x : x*x,3.45,3.2,0)
Traceback (most recent call last):
    ...
AssertionError: precision should be positive integer your input : 0
>>> simpson_integration(lambda x : x*x,3.45,3.2,-1)
Traceback (most recent call last):
    ...
AssertionError: precision should be positive integer your input : -1
maths.numerical_analysis.integration_by_simpson_approx.N_STEPS = 1000