Definite Integral

Overview

Definition

For a given complex function {% w(t) %} of a real parameter, {% t \in \mathbb{R} %},
{% w(t) = u(t) + i v(t) %}
the definite integral is defined to be
{% \int_a^b w(t)dt = \int_a^b u(t) dt + i \int_a^b v(t) dt %}

Implementation

The quad function in the SciPy integration module natively supports complex-valued functions. You just need to pass the argument complex_func=True.
import numpy as np from scipy.integrate import quad # Define a complex-valued function def integrand(x): return np.exp(1j * x) # Integrate over a real interval result, error = quad(integrand, 0, np.pi, complex_func=True) print("Result:", result) # Output: (0+2j) (within numerical precision)