On 14 February 2016 at 15:17, Andrew Corrigan <[email protected]> wrote:
> I'm having trouble computing a definite integral involving the sqrt of a
> non-negative expression, as implemented below (computing the length of a
> quadratic line in 2D). It seems to fail. I've generally had success using
> sympy for integration, except for when a sqrt is present.
>
> If anyone has any advice on how to make this work, I would appreciate it
> tremendously. Thanks in advance!
>
> from sympy import *
> x0,x1,x2,y0,y1,y2,xi = symbols('x0 x1 x2 y0 y1 y2 xi', real=True)
> f_squared = (-4*x0*xi + 3*x0 - 4*x1*xi + x1 + 8*x2*xi - 4*x2)**2 + (4*xi*y0
> + 4*xi*y1 - 8*xi*y2 - 3*y0 - y1 + 4*y2)**2
> f = sqrt(f_squared)
> integrate(f, (xi,0,1))
Distilling this down you want to compute the integral of the square
root of a quadratic. Sympy can do this in some simple cases:
>>> sqrt(1 + x**2).integrate(x)
________
╱ 2
x⋅╲╱ x + 1 asinh(x)
───────────── + ────────
2 2
However it fails for slightly more complicated cases:
>>> sqrt(1 + x + x**2).integrate(x)
⌠
⎮ ____________
⎮ ╱ 2
⎮ ╲╱ x + x + 1 dx
⌡
This second form can always be reduced to the first by completing the
square and changing variables. It seems that sympy is currently unable
to do that though :(
--
Oscar
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAHVvXxS5ys%2Bkfmz1-ZM3ekadA-gwwQ9e%2BDSGd1P4oXAkcKFn%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.