-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Description
I want to calculate integral located internally of the integral with imaginary numbers.
My code:
from scipy.integrate import quad
import numpy as np
import scipy
from scipy.special import jv
import math
import quadpy
def M_r(z):
print("z:",z)
return math.sqrt(z*z)
def integral_P(z):
print("Calling function, z=",z)
return (M_r(z)*np.exp(1j))
Integral = quadpy.quad(integral_P, 0, 1, limit=10)
print("Quadpy",Integral)
When I use scipy quad integration:
Integral = quad(integral_P, 0, 1, limit=10)
In the printout z values are single values, nor numpy array:
Calling function, z= 0.013046735741414128
z: 0.013046735741414128
Calling function, z= 0.9869532642585859
z: 0.9869532642585859
Calling function, z= 0.06746831665550773
z: 0.06746831665550773
but on other hand I have casting problem:
ComplexWarning: Casting complex values to real discards the imaginary part
return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
So I want to use quadpy.quad to deal with imaginary numbers. When I run this code, I have error:
Exception has occurred: TypeError
only size-1 arrays can be converted to Python scalars
And the printout is:
Calling function, z= [0.00217142 0.01304674 0.03492125 0.06746832 0.10959114 0.16029522
0.21862143 0.2833023 0.35280357 0.42556283 0.5 0.57443717
0.64719643 0.7166977 0.78137857 0.83970478 0.89040886 0.93253168
0.96507875 0.98695326 0.99782858]
z: [0.00217142 0.01304674 0.03492125 0.06746832 0.10959114 0.16029522
0.21862143 0.2833023 0.35280357 0.42556283 0.5 0.57443717
0.64719643 0.7166977 0.78137857 0.83970478 0.89040886 0.93253168
0.96507875 0.98695326 0.99782858]
Quadpy should pass single z values, over iterations, not entire numpy array. How can I solve this issue? The type of z is:
z: <class 'numpy.ndarray'>
After some tests I noticed that numpy array is passed also to internal M_r(z) function even if in the main function integral_P there are no imaginary numbers.
Metadata
Metadata
Assignees
Labels
No labels