SciPy - integrate.quad_vec() Method



The SciPy integrate.quad_vec() method is used to calculate the definite integrals of vector-value function. The vector value is a single numerical function which play the fundamental role in statistics calculation. The concept of vector is used to perform the task in Machine Learning.

Syntax

Following is the syntax of the SciPy integrate.quad_vec() method −

scipy.integrate.quad_vec(func, a, b)

Parameters

This method accepts the following parameter −

  • func: This is a paramter to perform the integral operation based on intervals.
  • a: Set the value of initial point.
  • b: Set the value of final limit.

Return value

This method return the result in the form of float values.

Example 1

Following is the SciPy integrate.quad_vec() method which illustrate the range intervals between 0 and pi and display the result.

import numpy as np
from scipy import integrate

# define the vector value function
def vector_fun(x):
    return np.array([np.sin(x), np.cos(x)])

# integrate from 0 to pi
res, err = integrate.quad_vec(vector_fun, 0, np.pi)

print("The result is:", res)
print("The error is:", err)

Output

The above code produces the following output −

The result is: [2.00000000e+00 2.22044605e-16]
The error is: 9.41333496923768e-14

Example 2

This example illustrate the quad_vec() method over a specified range to perform the vector numerical integration. So, below the custom function vector_func() returns the three vector values with respect to x.

import numpy as np
from scipy.integrate import quad_vec

# define the vector value function
def vector_fun(x):
    return np.array([x, x**2, np.exp(x)])

# Integrate from 1 to 2
res, err = quad_vec(vector_fun, 1, 2)

print("The result is:", res)
print("The error is:", err)

Output

The above code produces the following output −

The result is: [1.5        2.33333333 4.67077427]
The error is: 1.8102941011273191e-13
scipy_reference.htm
Advertisements