ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 27 Sep 2011 02:21:03 +0200numeric approximation??https://ask.sagemath.org/question/8345/numeric-approximation/So I have an equation that solved (symbolically) looks something like this:
r == 1/488486532917088881338043645348028612608*sqrt(1271541785242875384103984923680382406444427305742938801212457) - 80406364132947/169706962694363951398912
and when I do anything to evaluate this numerically I get a TypeError? Right now I am copying and pasting this output into wolfram alpha, but really there has to be a better way?
Furthermore if I try to evaluate the equation with find_root(...) I get this error:
File "expression.pyx", line 984, in sage.symbolic.expression.Expression.__float__ (sage/symbolic/expression.cpp:5596)
TypeError: unable to simplify to float approximation
?!Mon, 26 Sep 2011 21:53:39 +0200https://ask.sagemath.org/question/8345/numeric-approximation/Comment by benjaminfjones for <p>So I have an equation that solved (symbolically) looks something like this:</p>
<p>r == 1/488486532917088881338043645348028612608*sqrt(1271541785242875384103984923680382406444427305742938801212457) - 80406364132947/169706962694363951398912</p>
<p>and when I do anything to evaluate this numerically I get a TypeError? Right now I am copying and pasting this output into wolfram alpha, but really there has to be a better way? </p>
<p>Furthermore if I try to evaluate the equation with find_root(...) I get this error:</p>
<p>File "expression.pyx", line 984, in sage.symbolic.expression.Expression.__float__ (sage/symbolic/expression.cpp:5596)
TypeError: unable to simplify to float approximation</p>
<p>?!</p>
https://ask.sagemath.org/question/8345/numeric-approximation/?comment=21195#post-id-21195Can you post the code that produces the solution r?Mon, 26 Sep 2011 23:11:05 +0200https://ask.sagemath.org/question/8345/numeric-approximation/?comment=21195#post-id-21195Answer by DSM for <p>So I have an equation that solved (symbolically) looks something like this:</p>
<p>r == 1/488486532917088881338043645348028612608*sqrt(1271541785242875384103984923680382406444427305742938801212457) - 80406364132947/169706962694363951398912</p>
<p>and when I do anything to evaluate this numerically I get a TypeError? Right now I am copying and pasting this output into wolfram alpha, but really there has to be a better way? </p>
<p>Furthermore if I try to evaluate the equation with find_root(...) I get this error:</p>
<p>File "expression.pyx", line 984, in sage.symbolic.expression.Expression.__float__ (sage/symbolic/expression.cpp:5596)
TypeError: unable to simplify to float approximation</p>
<p>?!</p>
https://ask.sagemath.org/question/8345/numeric-approximation/?answer=12692#post-id-12692My guess is that you're trying to call .n() or float not on the number but on the _equation_. For example:
sage: ans = solve((x-11/sqrt(13))**2,x)
sage: ans
[x == 11/13*sqrt(13)]
sage: ans[0]
x == 11/13*sqrt(13)
sage: ans[0].n()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
[...]
/Applications/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._numerical_approx (sage/symbolic/expression.cpp:17880)()
TypeError: cannot evaluate symbolic expression numerically
You really want to get at the expression on the right:
sage: ans[0].rhs().n()
3.05085107923876
or maybe
sage: ans = solve((x-11/sqrt(13))**2,x,solution_dict=True)
sage: ans[0]
{x: 11/13*sqrt(13)}
sage: ans[0][x]
11/13*sqrt(13)
sage: ans[0][x].n()
3.05085107923876
Mon, 26 Sep 2011 23:47:30 +0200https://ask.sagemath.org/question/8345/numeric-approximation/?answer=12692#post-id-12692Comment by nalaurethsulfate for <p>My guess is that you're trying to call .n() or float not on the number but on the _equation_. For example:</p>
<pre><code>sage: ans = solve((x-11/sqrt(13))**2,x)
sage: ans
[x == 11/13*sqrt(13)]
sage: ans[0]
x == 11/13*sqrt(13)
sage: ans[0].n()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
[...]
/Applications/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._numerical_approx (sage/symbolic/expression.cpp:17880)()
TypeError: cannot evaluate symbolic expression numerically
</code></pre>
<p>You really want to get at the expression on the right:</p>
<pre><code>sage: ans[0].rhs().n()
3.05085107923876
</code></pre>
<p>or maybe</p>
<pre><code>sage: ans = solve((x-11/sqrt(13))**2,x,solution_dict=True)
sage: ans[0]
{x: 11/13*sqrt(13)}
sage: ans[0][x]
11/13*sqrt(13)
sage: ans[0][x].n()
3.05085107923876
</code></pre>
https://ask.sagemath.org/question/8345/numeric-approximation/?comment=21194#post-id-21194Wow thanks. Worked like a charm. I was thinking that may be my problem, but didn't know how to access that. Thanks again.Tue, 27 Sep 2011 02:21:03 +0200https://ask.sagemath.org/question/8345/numeric-approximation/?comment=21194#post-id-21194