On Tue, Apr 7, 2009 at 3:02 PM, Greg Marks <[email protected]> wrote:
>
> SAGE gave me this strange result when attempting to integrate a
> piecewise-defined function:
>
The following is the only thing SAge has for piecewise functions:
sage: f = Piecewise([[(0,pi/2),x],[(pi/2,pi),sin(x)]])
sage: f.integral()
Piecewise defined function with 2 parts, [[(0, pi/2), x^2/2], [(pi/2,
pi), pi^2/8 - cos(x)]]
Trying to define a piecewise function with "def" will only define a
*Python* function,
not a symbolic function, so it can't be integrated.
William
> sage: v,x=var('v,x')
> sage: def chi_squared_pdf(x,v):
> ....: if x > 0:
> ....: return 1/( 2^(v/2) * gamma(v/2) ) * x^(v/2 - 1) * exp(-
> x/2)
> ....: else:
> ....: return 0
> ....:
> sage: integrate(chi_squared_pdf(x,24), x, 364/10, infinity)
> 0
>
> The error goes away when I try this:
>
> sage: def f(x,v): return 1/( 2^(v/2) * gamma(v/2) ) * x^(v/2 - 1) *
> exp(-x/2)
> ....:
> sage: integrate(f(x,24), x, 364/10, infinity)
> 560147352029072813039*e^(-91/5)/139218750000000
>
> SAGE does seem to have accepted my definition of the function
> chi_squared_pdf:
>
> sage: chi_squared_pdf(364/10,24)
> 506240953553539690213*e^(-91/5)/556875000000000
>
> I'm not sure why it won't integrate it. Am I doing something wrong?
>
> Sincerely,
> Greg
>
> ------------------------------------------------
> | Greg Marks |
> | Department of Mathematics and Computer Science |
> | St. Louis University |
> | St. Louis, MO 63103-2007 |
> | U.S.A. |
> | |
> | Phone: (314)977-7206 |
> | Fax: (314)977-1452 |
> | Web: http://math.slu.edu/~marks |
> ------------------------------------------------
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---