-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double integration issue - passing numpy array instead of single values #414
Comments
For me, your code correctly gives
and then errors out because |
I changed math.sqrt to np.sqrt, but now I have another problem - quad divided to real and imaginary parts and quadpy calculating both parts give different results - why?
The output is:
I observed that if I change phi_0 to:
results are almost same:
|
Different algorithms, different results. Both results are in the order of machine precision, and they differ by less than 10^{-11}. The error indicates that, too. Everything seems in order. |
Thank you for the comment. I have another issue with integrating integral. My code is: from scipy.integrate import quad
import numpy as np
import scipy
from scipy.special import jv
import math
import quadpy
B=8
m=4
M_x = 0.3
M_T = 1
theta=0.3
def f_D(x, z):
print("f_D:",z)
return 1*np.exp(1j*x)*z
def M_r(z):
print("M_r",z)
return np.sqrt(z*z)
def psi_D(z):
print("psi_D",z)
return quad(f_D, -0.5, 0.5, limit=50, args=(z))[0]
def integral_P_Vm(z):
print("Calling function, z=",z)
return M_r(z)**2*np.exp(1j)*jv(m*B, ((m*B*z*np.sin(theta)/(1-M_x*np.cos(theta)))))*2*psi_D(z)
Quad_integral = quad(integral_P_Vm, 0, 1, limit=100)
Quadpy_integral = quadpy.quad(integral_P_Vm, 0, 1, limit=100)
print("Quad",Quad_integral)
print("Quadpy",Quadpy_integral) Scipy Quad integrates (but with no imaginary parts).
The last output is following:
|
It's scipy.quad that gives that error. |
When I change:
the
The issue is that single values of z should be passed to |
You can loop then. |
I tried looping with an error:
Output is:
|
Always post the full code, I don't want to make any guesses. |
Full code:
Error is at line 26:
Also I am not sure if the integral |
What is
? You FYI: I won't have any more time to look at this problem until next week or so. |
This is loop over z values in order to calculate internal function scipy.quad handles loops automatically, but it doesn't handle imaginary numbers. How should I loop in quadpy manually? Currently I have
error. FYI: OK. |
I solved above problem by changing (z) to [z]:
But now I have another issue. I have following code:
At first I have shape (21,) for both variables x and z. But during calculations the shape of x variable grows to (42,) and I have error:
in the line: |
Hi @nschloe do you know maybe how to resolve this issue? |
I don't have much time these days. I can point you to https://github.com/nschloe/quadpy/wiki/Dimensionality-of-input-and-output-arrays. |
I want to calculate integral located internally of the integral with imaginary numbers.
My code:
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:
but on other hand I have casting problem:
So I want to use quadpy.quad to deal with imaginary numbers. When I run this code, I have error:
And the printout is:
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.
The text was updated successfully, but these errors were encountered: