On Mon, 20 Feb 2012 10:39:11 -0500 Michael Orlitzky <mich...@orlitzky.com> wrote:
> On 02/19/12 19:58, Mike wrote: > > When I run: > > > > x,y=var('x,y', domain=RR) > > solve(2.0*x+3.0*y==4.0, y) > > > > I get > > > > [y == -2/3*x + 4/3] > > > > but I would like to get > > > > [y == -0.666666666666666*x + 1.3333333333333] > > > > How can I do this? > > > > Wild guess: the float coefficients are coerced to QQ, because > otherwise numerical inaccuracy would prevent us from finding a > solution. For example, > > (0.333333... + 0.666666...)*x > > might not equal x. > > For a workaround, someone recently showed me this. You would call > `symbolic_approx` on your result. > > --- > > class NumericEvaluator(Converter): > > def arithmetic(self, ex, operator): > return reduce(operator, map(self, ex.operands())) > > def pyobject(self, ex, obj): > return ex.n() > > def symbol(self, ex): > return SR(ex) > > def symbolic_approx(expr): > ne = NumericEvaluator() > return ne(expr) > Or you can do this: sage: t = -2/3*x + 4/3 sage: t._convert(RR) -0.666666666666667*x + 1.33333333333333 Cheers, Burcin -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org