Hi,

Thank you; that solution fits the matter perfectly.

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...)

regards & many thanks
john perry

On Nov 30, 12:55 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> This is an instance ofhttp://trac.sagemath.org/sage_trac/ticket/847.
>  I / we haven't had time to fix that one, but hopefully we can get to
> it tomorrow.  For now, you should make sure that f is an actual Python
> function.
>
> sage: f = lambda x: x
> sage: Midpoint_Riemann_Sums(0, 5, f, 1000)
> 12.5250000000000
> sage: def f(x):
> ....:     return x
> ....:
> sage: Midpoint_Riemann_Sums(0, 5, f, 1000)
> 12.5250000000000
>
> --Mike
>
> On Nov 30, 2007 10:08 AM, David Joyner <[EMAIL PROTECTED]> wrote:
>
>
>
> > Again, I don't understand the bug but piecewise seems to work better using
> > lambda functions.
>
> > sage: f = lambda x: x
> > sage: fp = Piecewise([[(10,20),f]])
> > sage: fp.riemann_sum_integral_approximation(993)
> > 148900/993
>
> > Next semester, when I have more time, I plan to revise piecewise.
> > Maybe I can look into the bug more then...
>
> > On Nov 30, 2007 10:49 AM, john_perry_usm <[EMAIL PROTECTED]> wrote:
>
> > > Thank you! The following code produces the same error.
>
> > > f = x
> > > fp = Piecewise([[(10,20),f]])
> > > fp.riemann_sum_integral_approximation(993)
>
> > > The student is doing this as an assignment for a class on how to write
> > > programs to solve problems in mathematics. (Newton's Method, Riemann
> > > sums, Fibonacci numbers, Traveling Salesman, etc.) She's not doing
> > > this because she needed SAGE to approximate a Riemann sum. They
> > > started with Maple, and now we're working on SAGE; I'd like to teach
> > > the class exclusively in SAGE one day.
>
> > > regards
> > > john perry
>
> > > On Nov 30, 9:00 am, "David Joyner" <[EMAIL PROTECTED]> wrote:
> > > > I'm not sure what the cause of the error is but, FYI, some Riemann sum 
> > > > stuff is
> > > > already implemented in piecewise.py.
>
> > > > On Nov 30, 2007 9:41 AM, john_perry_usm <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi,
>
> > > > > One of my students was writing a procedure to implement a Midpoint
> > > > > Riemann Sum in SAGE. The procedure that she devised is given below,
> > > > > and it looks reasonable enough to me. Unfortunately it generates a
> > > > > SAGE exception (AttributeError, line 2051 of calculus.py) under
> > > > > certain bizarre circumstances; try for example a=10,b=20,f=x,n=991
> > > > > (which works fine) then n=992 with the same a,b,f.
>
> > > > > Any assistance would be appreciated. Maybe I don't know Python well
> > > > > enough? :-) I have verified the exception using both SAGE-2.8.7 on
> > > > > Fedora Core 7 and SAGE-2.8.13 on Windows.
>
> > > > > regards
> > > > > john perry
>
> > > > > Her procedure:
>
> > > > > 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
>
> > > > > The error message:
>
> > > > > Traceback (most recent call last):
> > > > >   File "/atlas/perry/sage_notebook/worksheets/apetrinec55/1/code/
> > > > > 71.py", line 4, in <module>
> > > > >     exec
> > > > > compile(ur'Midpoint_Riemann_Sums(Integer(10),Integer(20),f,Integer(1000))'
> > > > > + '\n', '', 'single')
> > > > >   File "/usr/local/sage-2.8.7-fedora_core_7-i686-Linux/data/extcode/
> > > > > sage/", line 1, in <module>
>
> > > > >   File "sage_object.pyx", line 87, in sage_object.SageObject.__repr__
> > > > >   File "/usr/local/sage-2.8.7-fedora_core_7-i686-Linux/local/lib/
> > > > > python2.5/site-packages/sage/calculus/calculus.py", line 2896, in
> > > > > _repr_
> > > > >     return self.simplify()._repr_(simplify=False)
> > > > >   File "/usr/local/sage-2.8.7-fedora_core_7-i686-Linux/local/lib/
> > > > > python2.5/site-packages/sage/calculus/calculus.py", line 2051, in
> > > > > simplify
> > > > >     S =
> > > > > evaled_symbolic_expression_from_maxima_string(self._maxima_init_())
> > > > >   File "/usr/local/sage-2.8.7-fedora_core_7-i686-Linux/local/lib/
> > > > > python2.5/site-packages/sage/calculus/calculus.py", line 3044, in
> > > > > _maxima_init_
> > > > >     return '(%s) %s (%s)' % (ops[0]._maxima_init_(),
>
> > > > > ...and then several hundred more of that last line.
--~--~---------~--~----~------------~-------~--~----~
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