On Nov 30, 2007 1:58 PM, Mike Hansen <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> > In Maple one typically write f:=x->x if one means a function instead
> > of an expression. Doing something similar in SAGE makes a *lot* of
> > sense, so I don't object inherently to the lambda notation, although
> > the default Python syntax ("lambda") is not intuitive to an "ordinary"
> > math student. A nice solution might be to introduce an intuitive SAGE
> > construction for functions. -- My $.02 (US $ so not as much lately as
> > it used to be...)
>
> Actually, now that I think about it, there is a "nice" way to create
> the function in Sage which I completely forgot about.
>
> sage: f(x) = x
> sage: Midpoint_Riemann_Sums(0,5,f,1000)
> 12.5250000000000
>
> I also put a patch up that make Sage work when you use "f = x".  It
> should get into the next release,
>

Yep, with the patch at
    http://trac.sagemath.org/sage_trac/ticket/847
your original code works.

sage: def Midpoint_Riemann_Sums(a,b,f,n):
....:       delta_x = (b-a)/(n*1.0)
....:   result = 0
....:   for i in range(1, n+1):
....:         xi = ((delta_x/2)+a)+(i*delta_x)
....:     result = result+f(xi)*delta_x
....:   return result
....:
sage: a=10;b=20;f=x;n=991
sage: Midpoint_Riemann_Sums(a,b,f,n)
150.100908173562
sage: Midpoint_Riemann_Sums(a,b,f,992)
150.100806451613
sage: Midpoint_Riemann_Sums(a,b,f,1000)
150.100000000000

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to