A mistake in vector_integrate

30 views
Skip to first unread message

Boris Al

unread,
Oct 2, 2025, 3:23:50 PM (8 days ago) Oct 2
to sympy
Hi everyone,

I found a mistake in function vectore_integrate, if you run debug, it opens up the integrals.py, then go to the line 105

 integrand = simplify(parametricfield*coeff) 

and you need to change it to 

 integrand = simplify(parametricfield*abs(coeff))

because if you integrate over a body and you use a certain parametrization, your programm needs to calculate the absolute value of the determinant of the jacobian of the transformation. Here in the code the absolute value was missing. Here below, a simple programm, where we integrate a function f(x,y,z)=1 over a 3d sphere, with famous parametrization. In first case we go with (phi, 0, pi) and in the second one with (phi, -pi/2, pi/2). In both cases we expect to get the same result, namely 4/3*pi (a volume of a 3d sphere with radius 1), but  we get different values, because of the missing abs() (the determinant of jacobian of transformation is -r^2*sin(phi)).


from sympy import sin, cos, pi
from sympy.vector import CoordSys3D, ParametricRegion, vector_integrate
from sympy.abc import r,theta, phi
C = CoordSys3D('C')


solidsphere1 = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
                            (phi, 0, pi), (theta, 0, 2*pi), (r, 0, 1))
a=vector_integrate(1, solidsphere1)
print(a)

solidsphere11 = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
                            (phi, -pi/2, pi/2), (theta, 0, 2*pi), (r, 0, 1))
b=vector_integrate(1, solidsphere11)
print(b)
Reply all
Reply to author
Forward
0 new messages