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.Sat, 17 Apr 2021 13:10:47 +0200Cannot evaluate symbolic expression to a numerical valuehttps://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/ I'm trying to do this:
```
(sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)).roots( ring=RealField(100))
```
Unfortunately I get the error in the title.
Also any other way of solving the above equation numerically would be appreciated. I was able to do it in maxima using `find_root` but was hoping for a better function (one that doesn't require specifying an interval). I couldn't use find_root in sage because it returns the error 'unable to simplify to float approximation' and ofcourse `solve` doesn't return explicit solutions.Fri, 16 Apr 2021 17:06:47 +0200https://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/Answer by rburing for <p>I'm trying to do this:
<code>
(sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)).roots( ring=RealField(100))
</code>
Unfortunately I get the error in the title.
Also any other way of solving the above equation numerically would be appreciated. I was able to do it in maxima using <code>find_root</code> but was hoping for a better function (one that doesn't require specifying an interval). I couldn't use find_root in sage because it returns the error 'unable to simplify to float approximation' and ofcourse <code>solve</code> doesn't return explicit solutions.</p>
https://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/?answer=56674#post-id-56674From the [documentation of `roots`](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html):
> Return roots of `self` that can be found exactly, possibly with multiplicities. Not all roots are guaranteed to be found.
> **Warning:**
This is *not* a numerical solver
and
> `ring` - a ring (default None): if not None, convert self to a polynomial over ring and find roots over ring
The latter explains why you get the error in the title: the expression is not a polynomial, so the conversion fails.
The expression itself is only defined as a real number if `y` is between 0 and 10 (due to the $\sqrt{y(10-y)}$), so:
sage: var('y')
sage: f = sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)
sage: f.find_root(0,10)
5.5672155196677675
sage: find_root(f,0,10)
5.5672155196677675
By plotting `f` you see that it's the only root.
In general there is no magic method to find an interval where a root may live. It is however always a good idea to check the domain of definition first.Fri, 16 Apr 2021 19:16:59 +0200https://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/?answer=56674#post-id-56674Comment by Emmanuel Charpentier for <p>From the <a href="https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html">documentation of <code>roots</code></a>:</p>
<blockquote>
<p>Return roots of <code>self</code> that can be found exactly, possibly with multiplicities. Not all roots are guaranteed to be found.</p>
<p><strong>Warning:</strong>
This is <em>not</em> a numerical solver</p>
</blockquote>
<p>and</p>
<blockquote>
<p><code>ring</code> - a ring (default None): if not None, convert self to a polynomial over ring and find roots over ring</p>
</blockquote>
<p>The latter explains why you get the error in the title: the expression is not a polynomial, so the conversion fails.</p>
<p>The expression itself is only defined as a real number if <code>y</code> is between 0 and 10 (due to the $\sqrt{y(10-y)}$), so:</p>
<pre><code>sage: var('y')
sage: f = sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)
sage: f.find_root(0,10)
5.5672155196677675
sage: find_root(f,0,10)
5.5672155196677675
</code></pre>
<p>By plotting <code>f</code> you see that it's the only root.</p>
<p>In general there is no magic method to find an interval where a root may live. It is however always a good idea to check the domain of definition first.</p>
https://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/?comment=56687#post-id-56687A visual exploration of the complex region around 0 suggests that the real root approximated by `rburing` is the only one "close to 0" :
complex_plot(lambda u:(sqrt(10*u*(10-u))+sqrt(1000)*acos(sqrt(u/10))-15*sqrt(2*6.673*10^(-11)*50000000000)),(-10,10),(-10,10))
![image description](/upfiles/16186578127568455.png)
A 3D plot of the modulus closer to the real root suggests that this root is indeed unique :
![image description](/upfiles/1618659513319731.png)
Further *analytical* work (finding majorants/minorants of moduli) may *prove* the absence of roots outside this region and the uniqueness of the real root.
This is left to the reader as an exercise ;-)...Sat, 17 Apr 2021 13:10:47 +0200https://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/?comment=56687#post-id-56687