If you are trying to have your students develop a symbolic library by themselves, programming something like n() would indeed be quite nontrivial, since you have to use a specific numeric algorithm to find an arbitrary precision approximation for any object that is in the library.
You could settle for a partial solution by casting to float, if you don't really need arbitrary precision. You could tell them to define the __float__ method for the objects in the module for which casting to float make sense. For things like integrals they could use a simple numerical method with error estimates. It would not be production code, but still a good exercise. If you want to use pure Python, you can "fake" it using sympy, which is a small symbolic library in Python. It has functionality analogous to n(), and has a nice interface to numpy/scipy (check the function lambdify). I use it with a numerical methods course where they have to learn pure Python (so I can't use Sage), to do things like computing the equations of motion from a Lagrangian and then solving the equations numerically. Felipe Martins Sent from my iPad > On May 14, 2017, at 6:22 PM, 'Jorge Garcia' via sage-edu > <[email protected]> wrote: > > This is an off shoot of a discussion in sagecell, but it's not really > sagecell specific, so here ya go: > > "Is there a way to implement something similar to numerical_approx() in > python, say with scipy or numpy? > > My AP Calculus BC students are doing a post AP Exam final project related to > solving free response questions from old AP exams using SAGE and also in > plain python. For example they are writing their own (numerical) versions of > find_root(), diff() and integrate(). I showed them a little bit of python and > they wrote their own newton's method, difference quotient and Riemann sum > algorithms. I set up an Ubuntu ssh server with python installed for them to > use for this purpose. > > All was going well until they asked me how to write their own n() method. > This is where I got stumped." > > Thanx in advance, > A. Jorge Garcia > -- > You received this message because you are subscribed to the Google Groups > "sage-edu" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sage-edu. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-edu" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-edu. For more options, visit https://groups.google.com/d/optout.
