Ask Your Question

Unable to Integrate function

asked 2022-10-14 02:49:24 +0200

greenburg gravatar image

I have a function and am able to integrate it just fine in Mathematica, but get the below error when trying to perform the integral in sagemath.

TypeError: Substitution using function-call syntax and unnamed arguments has been removed. You can use named arguments instead, like EXPR(x=..., y=...)

I will try and comment my Mathematica code and output because I don't have enough karma to post a link.

My sagemath code is below. I tried printing out a few different ways to integrate but never got a way that didn't give a depreciation error.


from sage.symbolic.integration.integral import indefinite_integral

a = var('a')

z = var('z')

q = var('q')

r = var('r')

R = var('R')

s = var('s')

f = (4/(a^3)((zq^2)/r-(zq^2)/rexp(-s(r-R)))r^2exp(-2r/a))



print(numerical_integral(f, 0, +Infinity))



edit retag flag offensive close merge delete


Here is the Mathematica code.

greenburg gravatar imagegreenburg ( 2022-10-14 02:49:52 +0200 )edit

Could you rewrite your f by putting * where multiplication is needed? (z*q instead of zq, etc.)

tolga gravatar imagetolga ( 2022-10-14 12:10:06 +0200 )edit

Following @tolga hint, can you confirm that f is $$-\frac{4 \, {\left(\frac{q^{2} z e^{\left({\left(R - r\right)} s\right)}}{r} - \frac{q^{2} z}{r}\right)} r^{2} e^{\left(-\frac{2 \, r}{a}\right)}}{a^{3}}$$ , as suggested by your typing ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-10-14 14:49:43 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2022-10-18 10:27:52 +0200

achrzesz gravatar image

updated 2022-10-18 11:00:46 +0200

If all parameters are positive, there are no problems with integrate

a, z, q, r, R, s = var("a, z, q, r, R, s")
Ex = (4/(a^3)*((z*q^2)/r-(z*q^2)/r*exp(-s*(r-R)))*r^2*exp(-2*r/a))
Im = integrate(Ex,(r,R,oo))
edit flag offensive delete link more

answered 2022-10-16 23:14:12 +0200

Emmanuel Charpentier gravatar image

updated 2022-10-16 23:16:18 +0200

Assuming that your integrand is :

a, z, q, r, R, s = var("a, z, q, r, R, s")
Ex = (4/(a^3)*((z*q^2)/r-(z*q^2)/r*exp(-s*(r-R)))*r^2*exp(-2*r/a))

i.e. : $$ \texttt{Ex}=-\frac{4 {\left(\frac{q^{2} z e^{\left({\left(R - r\right)} s\right)}}{r} - \frac{q^{2} z}{r}\right)} r^{2} e^{\left(-\frac{2 \, r}{a}\right)}}{a^{3}} $$

neither giac, fricas nor sympy can give a closed-form expression to this integral ; using maxima leads to a situation where the same asumptions are queried in loop.

However, mathematica (or the gratis (but not free) Wolfram engine) gives an answer :

sage: Im = mathematica.Integrate(Ex, (r, R, oo)) ; Im
ConditionalExpression[(q^2*s*(4*(a + R) + a*(a + 2*R)*s)*z)/
  (a*E^((2*R)/a)*(2 + a*s)^2), Re[a] > 0 && Re[2/a + s] > 0]

which can be manually ang roughly (for now) translated as Im[1].sage() if a.real()>0 and (2/a+s).real()>0 else None.

This situation could be quite enhanced if/when logical symbolic functions are added to Sage (work in progress...).

Note : The difficulty does not lies in the computation of an antiderivative (all engines can do that), but in the computation of the limits for r=oo...


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-10-14 02:49:24 +0200

Seen: 239 times

Last updated: Oct 18 '22