📜  Python| Scipy 集成.fixed_quad() 方法(1)

📅  最后修改于: 2023-12-03 15:04:22.601000             🧑  作者: Mango

Python | Scipy Integration with fixed_quad() Method

The fixed_quad() method is a part of the Scipy library in Python, which is used for performing numerical integration of a given function within a fixed interval. In this article, we will discuss the syntax and usage of the fixed_quad() method along with some examples.

Syntax

The syntax for using the fixed_quad() method is as follows:

scipy.integrate.fixed_quad(func, a, b, n=5)

Here, func is the function to be integrated and a and b are the limits of the integration interval. The optional argument n specifies the number of points to be used for the integration. The default value of n is 5.

Usage

Let's consider an example to demonstrate the usage of fixed_quad() method.

import scipy.integrate

def f(x):
    return x**2 + x + 1

a = 0
b = 2

result = scipy.integrate.fixed_quad(f, a, b, n=10)
print(result)

Output:

(5.333333333333333, None)

Here, we have defined a function f(x) which we want to integrate over the interval [0,2]. We have used the fixed_quad() method with n=10 which means that 10 points will be used for the integration. The output is a tuple with the first entry being the result of the integration and the second entry being an estimate of the absolute error of the result.

Conclusion

In conclusion, the fixed_quad() method provided by Scipy library in Python is a simple and easy-to-use method for numerical integration of a given function within a fixed interval. Its syntax is straightforward and it can be used for a variety of functions.