How do I get a numeric approximation for symbolic expressions that have 
variables?  I want to leave the variables alone, but get numeric 
approximations for all constants.  For example, here's how it works in 
mathematica:

In[1]:= a:=1+Sqrt[2]*x

In[2]:= a

Out[2]= 1 + Sqrt[2] x

In[3]:= N[a]

Out[3]= 1. + 1.41421 x


However, the corresponding thing does not work in Sage:

sage: a=1+sqrt(2)*x
sage: a
sqrt(2)*x + 1
sage: n(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/grout/<ipython console> in <module>()

/home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/misc/functional.py
 
in numerical_approx(x, prec, digits)

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in numerical_approx(self, prec, digits)
    1300         except TypeError:
    1301             # try to return a complex result
-> 1302             approx = self._complex_mpfr_field_(ComplexField(prec))
    1303
    1304         return approx

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _complex_mpfr_field_(self, field)
    4852             0
    4853         """
-> 4854         return self._convert(field)
    4855
    4856     def _complex_double_(self, field):

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _convert(self, typ)
    4786                 raise
    4787             else:
-> 4788                 return typ(g)
    4789         return self._operator(*fops)
    4790

/home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py
 
in __call__(self, x, im)

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _complex_mpfr_field_(self, field)
    4852             0
    4853         """
-> 4854         return self._convert(field)
    4855
    4856     def _complex_double_(self, field):

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _convert(self, typ)
    4780         """
    4781         try:
-> 4782             fops = [typ(op) for op in self._operands]
    4783         except TypeError:
    4784             g = self.simplify()

/home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py
 
in __call__(self, x, im)

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _complex_mpfr_field_(self, field)
    4852             0
    4853         """
-> 4854         return self._convert(field)
    4855
    4856     def _complex_double_(self, field):

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _convert(self, typ)
    4780         """
    4781         try:
-> 4782             fops = [typ(op) for op in self._operands]
    4783         except TypeError:
    4784             g = self.simplify()

/home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py
 
in __call__(self, x, im)

/home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py 
in _complex_mpfr_field_(self, field)
    1453
    1454     def _complex_mpfr_field_(self, field):
-> 1455         raise TypeError
    1456
    1457     def _complex_double_(self, C):

TypeError:


This came up today when I was trying to convince the class that a rather 
complicated looking taylor polynomial was really just a nice polynomial, 
even though the coefficients looked really complicated.

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to