ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 28 Apr 2011 08:10:54 -0500Numerical approximation for expression coefficientshttp://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/I currently have an equation that looks like
x = 4/5*(4*y - 3)*z - 1/3
How can I get Sage to convert the coefficients to numerical approximations? I want to end up with something like
x = 0.8*(4*y - 3)*z - 0.333333333
I tried x.n(), but that only gives a "cannot evaluate symbolic expression numerically" error. Also x*1.0 doesn't do anything.Thu, 28 Apr 2011 00:38:22 -0500http://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/Comment by kcrisman for <p>I currently have an equation that looks like</p>
<p>x = 4/5<em>(4</em>y - 3)*z - 1/3</p>
<p>How can I get Sage to convert the coefficients to numerical approximations? I want to end up with something like</p>
<p>x = 0.8<em>(4</em>y - 3)*z - 0.333333333</p>
<p>I tried x.n(), but that only gives a "cannot evaluate symbolic expression numerically" error. Also x*1.0 doesn't do anything.</p>
http://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/?comment=21778#post-id-21778Since 1.2*x does what you want (well, except being multiplied by 1.2!), but not 1.0*x, I wonder if there is a bug here. See http://groups.google.com/group/sage-devel/browse_thread/thread/b6ab1e4499b07167# for a post about this on sage-devel.Thu, 28 Apr 2011 03:13:05 -0500http://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/?comment=21778#post-id-21778Answer by Kelvin Li for <p>I currently have an equation that looks like</p>
<p>x = 4/5<em>(4</em>y - 3)*z - 1/3</p>
<p>How can I get Sage to convert the coefficients to numerical approximations? I want to end up with something like</p>
<p>x = 0.8<em>(4</em>y - 3)*z - 0.333333333</p>
<p>I tried x.n(), but that only gives a "cannot evaluate symbolic expression numerically" error. Also x*1.0 doesn't do anything.</p>
http://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/?answer=12324#post-id-12324If $x$ is to be treated as a polynomial, then the following might suit your needs:
sage: var('y z')
(y, z)
sage: x = 4/5*(4*y - 3)*z - 1/3
sage: x.polynomial(RR)
3.20000000000000*y*z - 2.40000000000000*z - 0.333333333333333
Try
sage: RR?
for more information about `RR`Thu, 28 Apr 2011 08:10:54 -0500http://ask.sagemath.org/question/8095/numerical-approximation-for-expression-coefficients/?answer=12324#post-id-12324