Solve integratals

32 views
Skip to first unread message

Tom van Woudenberg

unread,
Jan 17, 2023, 5:39:23 AM1/17/23
to sympy
Hi there,

I'm trying to symbolically evaluate an integral with SymPy:

import sympy as sp
q, L, H = sp.symbols('q L H',positive=True,real=True)
x = sp.symbols('x',real=True)
Lexact = sp.integrate(sp.sqrt((L*q/(2*H) - q*x/H)**2 + 1),(x,0,L))
print(Lexact)


The result is:
Integral(sqrt(4*H**2 + L**2*q**2 - 4*L*q**2*x + 4*q**2*x**2), (x, 0, L))/(2*H)
So the integral isn't evaluated.

It should evalute to (4*H**2*arcsinh(q*L/(2*H))+q*L*sqrt(L882*q**2+4*H**2))/(4*q*H)

When substituting values for q, L and H, the evaluation is correct:
Lexact = sp.integrate(sp.sqrt((L*q/(2*H) - q*x/H)**2 + 1).subs([(q,5),(L,10),(H,60)]),(x,0,10))
print L(exact)
gives:
12*asinh(5/12) + 65/12

Does anyone has an idea on how to solve this?

Oscar Benjamin

unread,
Jan 17, 2023, 6:31:43 AM1/17/23
to sy...@googlegroups.com
On Tue, 17 Jan 2023 at 10:39, 'Tom van Woudenberg' via sympy
<sy...@googlegroups.com> wrote:
>
> Hi there,
>
> I'm trying to symbolically evaluate an integral with SymPy:
>
> import sympy as sp
> q, L, H = sp.symbols('q L H',positive=True,real=True)
> x = sp.symbols('x',real=True)
> Lexact = sp.integrate(sp.sqrt((L*q/(2*H) - q*x/H)**2 + 1),(x,0,L))
> print(Lexact)
>
> The result is:
> Integral(sqrt(4*H**2 + L**2*q**2 - 4*L*q**2*x + 4*q**2*x**2), (x, 0, L))/(2*H)
> So the integral isn't evaluated.

Which version of sympy are you using?

I just tried sympy 1.11.1 and also latest master and the integral does evaluate:

In [1]: import sympy as sp
...: q, L, H = sp.symbols('q L H',positive=True,real=True)
...: x = sp.symbols('x',real=True)
...: Lexact = sp.integrate(sp.sqrt((L*q/(2*H) - q*x/H)**2 + 1),(x,0,L))
...: print(Lexact)
-(-H**2*asinh(L*q/(2*H))/q - L*sqrt(4*H**2 + L**2*q**2)/4)/(2*H) +
(H**2*asinh(L*q/(2*H))/q + L*sqrt(4*H**2 + L**2*q**2)/4)/(2*H)


> It should evalute to (4*H**2*arcsinh(q*L/(2*H))+q*L*sqrt(L882*q**2+4*H**2))/(4*q*H)

I'm guessing that L882 is supposed to be L**2 because then it matches
what I get from sympy:

In [3]: print(Lexact.factor())
(4*H**2*asinh(L*q/(2*H)) + L*q*sqrt(4*H**2 + L**2*q**2))/(4*H*q)

--
Oscar

Oscar Benjamin

unread,
Jan 17, 2023, 6:37:49 AM1/17/23
to sy...@googlegroups.com
On Tue, 17 Jan 2023 at 11:31, Oscar Benjamin <oscar.j....@gmail.com> wrote:
>
> On Tue, 17 Jan 2023 at 10:39, 'Tom van Woudenberg' via sympy
> <sy...@googlegroups.com> wrote:
> >
> > Hi there,
> >
> > I'm trying to symbolically evaluate an integral with SymPy:
>
> Which version of sympy are you using?
>
> I just tried sympy 1.11.1 and also latest master and the integral does evaluate:

Looks like it was fixed by this PR for the 1.11 release:
https://github.com/sympy/sympy/pull/23530

--
Oscar

Tom van Woudenberg

unread,
Jan 17, 2023, 7:52:38 AM1/17/23
to sympy
You're correct, I was running SymPy version 1.10.1. Thank you!

Op dinsdag 17 januari 2023 om 12:37:49 UTC+1 schreef Oscar:
Reply all
Reply to author
Forward
0 new messages