ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 18 Oct 2020 19:05:23 -0500plot of sine, parabola intersection works but solve makes no sensehttps://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/When I plot a sine and parabola I get two obvious intersections
plot(x^2-5,-10,10,ymax=20) + plot(sin(x),-10,10)
But when I solve to get the two numeric x values, the answer makes no sense.
solve(x^2-5==sin(x),x)
[x == -sqrt(sin(x) + 5), x == sqrt(sin(x) + 5)]
![image description](/upfiles/16030024791456171.png)Sun, 18 Oct 2020 01:14:31 -0500https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/Answer by rburing for <p>When I plot a sine and parabola I get two obvious intersections</p>
<pre><code>plot(x^2-5,-10,10,ymax=20) + plot(sin(x),-10,10)
</code></pre>
<p>But when I solve to get the two numeric x values, the answer makes no sense.</p>
<pre><code>solve(x^2-5==sin(x),x)
[x == -sqrt(sin(x) + 5), x == sqrt(sin(x) + 5)]
</code></pre>
<p><img alt="image description" src="/upfiles/16030024791456171.png"></p>
https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?answer=53962#post-id-53962It makes sense: it tried to solve symbolically, and it didn't get very far (it isolated the square, and took ± the square root).
You don't want to solve symbolically but numerically. You want to find the two real zeros of `x^2 - 5 - sin(x)`, and from the picture you (roughly) know intervals where these are located, so you can use [find_root](https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_root):
sage: find_root(x^2 - 5 - sin(x), -5, 0)
-2.025211637444818
sage: find_root(x^2 - 5 - sin(x), 0, 5)
2.3846766601465696Sun, 18 Oct 2020 05:09:15 -0500https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?answer=53962#post-id-53962Comment by dazedANDconfused for <p>It makes sense: it tried to solve symbolically, and it didn't get very far (it isolated the square, and took ± the square root).</p>
<p>You don't want to solve symbolically but numerically. You want to find the two real zeros of <code>x^2 - 5 - sin(x)</code>, and from the picture you (roughly) know intervals where these are located, so you can use <a href="https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_root">find_root</a>:</p>
<pre><code>sage: find_root(x^2 - 5 - sin(x), -5, 0)
-2.025211637444818
sage: find_root(x^2 - 5 - sin(x), 0, 5)
2.3846766601465696
</code></pre>
https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53969#post-id-53969Most equations have no clean solution and must be evaluated with numerical approximations. This is one of them. [Even polynomials can cause problems](https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem).Sun, 18 Oct 2020 19:05:23 -0500https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53969#post-id-53969Comment by cybervigilante for <p>It makes sense: it tried to solve symbolically, and it didn't get very far (it isolated the square, and took ± the square root).</p>
<p>You don't want to solve symbolically but numerically. You want to find the two real zeros of <code>x^2 - 5 - sin(x)</code>, and from the picture you (roughly) know intervals where these are located, so you can use <a href="https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_root">find_root</a>:</p>
<pre><code>sage: find_root(x^2 - 5 - sin(x), -5, 0)
-2.025211637444818
sage: find_root(x^2 - 5 - sin(x), 0, 5)
2.3846766601465696
</code></pre>
https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53966#post-id-53966Can you only get this numerically or is there some form of advanced math that could solve a trig/algebra equivalence? I couldn't think of a way to do it by hand.Sun, 18 Oct 2020 14:34:08 -0500https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53966#post-id-53966Comment by cybervigilante for <p>It makes sense: it tried to solve symbolically, and it didn't get very far (it isolated the square, and took ± the square root).</p>
<p>You don't want to solve symbolically but numerically. You want to find the two real zeros of <code>x^2 - 5 - sin(x)</code>, and from the picture you (roughly) know intervals where these are located, so you can use <a href="https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_root">find_root</a>:</p>
<pre><code>sage: find_root(x^2 - 5 - sin(x), -5, 0)
-2.025211637444818
sage: find_root(x^2 - 5 - sin(x), 0, 5)
2.3846766601465696
</code></pre>
https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53965#post-id-53965Thanks. Although it's odd that plot can "solve" it but solve cannot. Maybe in a future iteration of sagemath, a symbolic failure will default to find_root.Sun, 18 Oct 2020 09:59:03 -0500https://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/?comment=53965#post-id-53965