Created
April 19, 2024 05:48
-
-
Save rezamarzban/da2d91863629621456038cd8db33c74d to your computer and use it in GitHub Desktop.
Numerical method integration of function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.integrate import quad | |
import sympy as sp | |
# Define the symbolic variable | |
x = sp.Symbol('x') | |
# Define the integrand as a sympy expression | |
integrand = sp.exp(-1j * x) / x | |
# Convert the sympy expression to a callable function | |
f = sp.lambdify(x, integrand, 'numpy') | |
# Define the integration limits | |
a = 1 | |
b = 1000 | |
# Perform numerical integration with complex data type | |
result, error = quad(f, a, b, complex_func=True) | |
print("Result:", result) | |
print("Estimated error:", error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment