Re: [sympy] Solving Integral with Symbolic Computation (Sympy), Division and Tricky Limits

2018-10-19 Thread Oscar Benjamin
On Fri, 19 Oct 2018 at 22:09, Aaron Meurer  wrote:
>
> You can pass the limits to integrate directly:
>
> >>> integrate(1/(x**2+y**2)**Rational(3,2), (y, -L/2, L/2))
> L/(x**3*sqrt(L**2/(4*x**2) + 1))
>
> It's generally recommended to do this as it isn't always correct to
> substitute the upper and lower values directly.  However, this result
> is equivalent to yours in this case, after pulling a 4 out of the
> square root.

Thinking about it the answer given by sympy above is only correct for x>0.

--
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/CAHVvXxQyYnv_wwKrWtFAXRsEnNp_immNYGc02rSVQ%3DuUUZfsiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Solving Integral with Symbolic Computation (Sympy), Division and Tricky Limits

2018-10-19 Thread Aaron Meurer
You can pass the limits to integrate directly:

>>> integrate(1/(x**2+y**2)**Rational(3,2), (y, -L/2, L/2))
L/(x**3*sqrt(L**2/(4*x**2) + 1))

It's generally recommended to do this as it isn't always correct to
substitute the upper and lower values directly.  However, this result
is equivalent to yours in this case, after pulling a 4 out of the
square root.

Aaron Meurer
On Fri, Oct 19, 2018 at 10:17 AM bb  wrote:
>
> A physics teacher on an online course [presented][1] this integral,
>
> $$
> = \frac{1}{4\pi\epsilon_0} \frac{Q x}{L}
> \int _{-L/2}^{L/2} \left(\frac{dy}{(x^2+y^2)^{3/2}} \right) \hat{x}
> $$
>
> and said she solved it with Wolfram Alpha, which gave
>
> $$
> = \frac{1}{4\pi\epsilon_0} \frac{Q}{x \sqrt{x^2 + (L/2)^2}}\hat{x}
> $$
>
> I was wondering how to solve this using any other symbolic software like 
> Sympy. I tried this for the indefinite integral,
>
> from sympy import integrate, sqrt, Symbol, pprint
> y = Symbol('y')
> x = Symbol('x')
> print (integrate('1/ ((x**2+y**2)**(3/2))',y))
>
> Result is
>
> y/(x**3*sqrt(1 + y**2/x**2))
>
> I plugged in the limits,
>
> from sympy import simplify
> L = Symbol('L')
> x = Symbol('x')
> simplify((L/2)/(x**3*sqrt(1 + (L/2)**2/x**2)) - \
>  (-L/2)/(x**3*sqrt(1 + (-L/2)**2/x**2)))
>
> I get
>
> 2*L/(x**3*sqrt(L**2/x**2 + 4))
>
> which does not look right. Does anyone have any experience solving integrals 
> such as the one above using symbolic software?
>
>   [1]: https://youtu.be/pJwg2Bk0BDE?t=1286
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> 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/16ad42e1-4972-46e2-8860-2bb96137f265%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/CAKgW%3D6%2BjxGY_Ts2TkQ7rpxA3D_xkYCbhUGg38yaHHKYsze0TBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Solving Integral with Symbolic Computation (Sympy), Division and Tricky Limits

2018-10-19 Thread Oscar Benjamin
On Fri, 19 Oct 2018 at 17:17, bb  wrote:
>
> A physics teacher on an online course [presented][1] this integral,

I haven't looked at the video but...

> from sympy import integrate, sqrt, Symbol, pprint
> y = Symbol('y')
> x = Symbol('x')
> print (integrate('1/ ((x**2+y**2)**(3/2))',y))
>
> Result is
>
> y/(x**3*sqrt(1 + y**2/x**2))
>
> I plugged in the limits,
>
> from sympy import simplify
> L = Symbol('L')
> x = Symbol('x')
> simplify((L/2)/(x**3*sqrt(1 + (L/2)**2/x**2)) - \
>  (-L/2)/(x**3*sqrt(1 + (-L/2)**2/x**2)))
>
> I get
>
> 2*L/(x**3*sqrt(L**2/x**2 + 4))
>
> which does not look right.

I think this is correct. It just looks a bit strange because sympy
hasn't written it in the form you would normally use. The normal way
to write the result of the integral would be

>>> res = y/ (x**2 * (x**2+y**2)**Rational(1/2))
>>> res
y/(x**2*sqrt(x**2 + y**2))

We can see that this also differentates back to what you started with:

>>> res.diff(y)
-y**2/(x**2*(x**2 + y**2)**(3/2)) + 1/(x**2*sqrt(x**2 + y**2))
>>> simplify(res.diff(y))
(x**2 + y**2)**(-3/2)

--
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/CAHVvXxRgWc6KBCJaOxY_Zf%2BxfEqAtcBNErJgkHzRQKWLAJLv6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.