It seems there is a bug:
[matlab]
>> integrand = 2*X*X + 2*Y*Y - 1
integrand =
2*X^2+2*Y^2-1
>> res = int(integrand, Y, -sqrt(1-X*X), sqrt(1-X*X))
res =
4*X^2*(1-X^2)^(1/2)+4/3*(1-X^2)^(3/2)-2*(1-X^2)^(1/2)
>> subs(res, X, 1)
ans =
     0
>> subs(res, X, 2)
ans =
   0.0000 +17.3205i
>>
[/matlab]

[sympy]
In [1]: from sympy import *
In [2]: X,Y,L = symbols('XYL')
In [3]: integrand = 2*X*X+2*Y*Y-1
In [4]: res = integrate(integrand, (Y, -sqrt(1-X**2), sqrt(1-X**2)))
In [5]: res
Out[5]: -2*(1 - X**2)**(1/2)*(1 - 2*X**2) + 4*(1 - X**2)**(3/2)/3
In [6]: res.subs({X: 1})
Out[6]: 0
In [7]: res.subs({X: 2})
Out[7]: 4*3**(1/2) + 14*I*3**(1/2)
In [8]: 14.0*3.0**(1./2.)
Out[8]: 24.248711305964282
[/sympy]

Note the real part of result is nonzero, and that the imaginary part
is different from the result that Matlab gives (really Maple under the
hood, at least in 2008a).

I'll file it under the issues.
~Luke

In [9]: res.subs({X: 2.})
Out[9]: 4*3**(1/2) + 14*I*3**(1/2)


On May 23, 7:31 am, Oyster <lepto.pyt...@gmail.com> wrote:
> that is a bad news :(
> I have thought to use py+sympy in my research work, but think I'd
> better turn to matlab now.
>
> On May 23, 2:57 am, Luke <hazelnu...@gmail.com> wrote:
>
> > I get a slightly different result when integrating in Matlab (2008a):
> > [matlab]
>
> > >> syms X Y L H K;
> > >> int(int(2*X*X+2*Y*Y-1, Y, -sqrt(1-X*X), sqrt(1-X*X)), X, L, 1)
>
> > ans =
>
> > -2/3*(1-L^2)^(1/2)*L*(L-1)*(1+L)
>
> > >> expand(ans)
>
> > ans =
>
> > 2/3*(1-L^2)^(1/2)*L-2/3*(1-L^2)^(1/2)*L^3
> > [/matlab]
>
> > In sympy, it seems like if you do the first integral, there are two
> > additive terms:>>> integrate(2*X*X+2*Y*Y-1, (Y, -(1-X**2)**Rational(1,2), 
> > (1-X**2)**Rational(1,2)) )
>
> > -2*(1 - X**2)**(1/2)*(1 - 2*X**2) + 4*(1 - X**2)**(3/2)/3>>> t1 = 
> > integrate(4*(1 - X**2)**(3/2)/3, (X,L,1))
>
> > 8/9 - 4*L/3 + 4*L**3/9>>> t2 = integrate(-2*(1 - X**2)**(1/2)*(1 - 2*X**2), 
> > (X,L,1))
>
> > -2/3 + 2*L - 4*L**3/3>>> t1+t2
>
> > 2/9 + 2*L/3 - 8*L**3/9
>
> > So if you perform the second integration on each term, one at a time,
> > it is fine, but when you try to do the whole thing, it doesn't like
> > it, as you pointed out.  I'm not sure why this would happen, it seems
> > like integrate should parse each additive term and try to integrate
> > it, if this were the case, the above example should work like
> > Matlab.
>
> > Additionally, it doesn't seem that the results are the same, so there
> > must be some sort of bug in integrate.
>
> > ~Luke
>
> > On May 22, 2:27 am, Oyster <lepto.pyt...@gmail.com> wrote:
>
> > > please note the dual-integrate result
> > > how can I get an advanced value in sympy? thanx
>
> > > [smypy]>>> from sympy import *
> > > >>> X,Y=symbols('XY', real=True)
> > > >>> integrate(2*X*X+2*Y*Y-1, (Y, -(1-X**2)**Rational(1,2), 
> > > >>> (1-X**2)**Rational(1,2)) )
>
> > > -2*(1 - X**2)**(1/2)*(1 - 2*X**2) + 4*(1 - X**2)**(3/2)/3>>> 
> > > integrate(integrate(2*X*X+2*Y*Y-1, (Y, -(1-X**2)**Rational(1,2), 
> > > (1-X**2)**Rational(1,2)) ), (X,L,1))
>
> > > Integral(-2*(1 - X**2)**(1/2)*(1 - 2*X**2) + 4*(1 - X**2)**(3/2)/3,
> > > (X, L, 1))>>> simplify(integrate(integrate(2*X*X+2*Y*Y-1, (Y, 
> > > -(1-X**2)**Rational(1,2), (1-X**2)**Rational(1,2)) ), (X,L,1)))
>
> > > Traceback (most recent call last):
> > >   File "<interactive input>", line 1, in ?
> > >   File "h:\pure_pylib\math\sympy\sympy\simplify\simplify.py", line
> > > 1079, in simplify
> > >   File "h:\pure_pylib\math\sympy\sympy\polys\polynomial.py", line 607,
> > > in cancel
> > >   File "h:\pure_pylib\math\sympy\sympy\core\basic.py", line 1437, in
> > > expand
> > >   File "h:\pure_pylib\math\sympy\sympy\core\basic.py", line 1372, in
> > > _eval_expand_basic
> > >   File "h:\pure_pylib\math\sympy\sympy\core\basic.py", line 374, in
> > > new
> > >   File "h:\pure_pylib\math\sympy\sympy\integrals\integrals.py", line
> > > 48, in __new__
> > > ValueError: Invalid integration variable or limits: (((X, (L, 1)),),)
> > > [/sympy]
>
> > > [matlab]
>
> > > >> syms X Y L H K;
> > > >> int(int(2*X*X+2*Y*Y-1, Y, -sqrt(1-X*X), sqrt(1-X*X)), X, L, 1)
>
> > > ans =
>
> > > 2/3*L*(1-L^2)^(3/2)
>
> > > >> int(2*X*X+2*Y*Y-1, Y, -sqrt(1-X*X), sqrt(1-X*X))
>
> > > ans =
>
> > > 4*X^2*(1-X^2)^(1/2)+4/3*(1-X^2)^(3/2)-2*(1-X^2)^(1/2)
>
> > > >> int(int(2*X*X+2*Y*Y-1, Y, -sqrt(1-X*X), sqrt(1-X*X)), X, L, 1)
>
> > > ans =
>
> > > 2/3*L*(1-L^2)^(3/2)
> > > [/matlab]- Hide quoted text -
>
> > - Show quoted text -
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to