Ask Your Question
1

Unable to Integrate function

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

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(indefinite_integral(f,r,R,+Infinity))

print(integrate(f,(r,R,+Infinity)))

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

print(f.integrate(r))

```

edit retag flag offensive close merge delete

Comments

Here is the Mathematica code.

greenburg gravatar imagegreenburg ( 2022-10-14 02:49:52 +0100 )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 +0100 )edit
1

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 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

achrzesz gravatar image

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

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

a, z, q, r, R, s = var("a, z, q, r, R, s")
assume(a>0);assume(R>0);assume(r>0) 
assume(s>0);assume(z>0);assume(q>0)
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))
factor(Im)
edit flag offensive delete link more
1

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

Emmanuel Charpentier gravatar image

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

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...

HTH,

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

Stats

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

Seen: 311 times

Last updated: Oct 18 '22