Skip to content

Instantly share code, notes, and snippets.

@rezamarzban
Created April 19, 2024 05:48
Show Gist options
  • Save rezamarzban/da2d91863629621456038cd8db33c74d to your computer and use it in GitHub Desktop.
Save rezamarzban/da2d91863629621456038cd8db33c74d to your computer and use it in GitHub Desktop.
Numerical method integration of function
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