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.Sat, 21 Oct 2017 09:07:42 -0500Numerically Solve a Symbolic Equationhttp://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/ Hello,
In truth, I am feeling like an idiot but it has been a long while since I have done math.
What I want to do is find the intersection points between a parabola and a circle. After I put both equations in x and set them equal, I have:
var('y')
solve (sqrt(16-x^2) - 1/4*x^2-1.28==0, x)
Problem is, I get the following for answers:
[x == -2/5*sqrt(25*sqrt(-x^2 + 16) - 32), x == 2/5*sqrt(25*sqrt(-x^2 + 16) - 32)]
If I need to numerically solve the equation, which I think I must do, how do I do it in Sage?
Fri, 16 Jun 2017 21:23:14 -0500http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/Answer by dan_fulea for <p>Hello, </p>
<p>In truth, I am feeling like an idiot but it has been a long while since I have done math. </p>
<p>What I want to do is find the intersection points between a parabola and a circle. After I put both equations in x and set them equal, I have: </p>
<pre><code>var('y')
solve (sqrt(16-x^2) - 1/4*x^2-1.28==0, x)
</code></pre>
<p>Problem is, I get the following for answers: </p>
<pre><code>[x == -2/5*sqrt(25*sqrt(-x^2 + 16) - 32), x == 2/5*sqrt(25*sqrt(-x^2 + 16) - 32)]
</code></pre>
<p>If I need to numerically solve the equation, which I think I must do, how do I do it in Sage? </p>
http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=39239#post-id-39239Alternatively, we can solve the corresponding polynomial equation over an explicitly declared numeric field:
sage: ( (16-x^2) - (1/4*x^2 + 1.28)^2 ).roots( ring=RR )
[(-2.63209850458273, 1), (2.63209850458273, 1)]
sage: ( (16-x^2) - (1/4*x^2 + 1.28)^2 ).roots( ring=RealField(300), multiplicities=False )
[-2.63209850458273472222645327989825104599024721420142212754062239578568429138110784195156834,
2.63209850458273472222645327989825104599024721420142212754062239578568429138110784195156834]
Let us compare with the values obtained in the spirit of the answer of [philipp7](https://ask.sagemath.org/users/23246/philipp7/)...
sage: [ sol[x].n()
....: for sol in solve( sqrt(16-x^2) - 1/4*x^2-1.28 == 0, x
....: , solution_dict=True
....: , to_poly_solve=True ) ]
[-2.63209850458273, 2.63209850458273]
Sat, 21 Oct 2017 09:07:42 -0500http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=39239#post-id-39239Answer by SageOfSixPaths for <p>Hello, </p>
<p>In truth, I am feeling like an idiot but it has been a long while since I have done math. </p>
<p>What I want to do is find the intersection points between a parabola and a circle. After I put both equations in x and set them equal, I have: </p>
<pre><code>var('y')
solve (sqrt(16-x^2) - 1/4*x^2-1.28==0, x)
</code></pre>
<p>Problem is, I get the following for answers: </p>
<pre><code>[x == -2/5*sqrt(25*sqrt(-x^2 + 16) - 32), x == 2/5*sqrt(25*sqrt(-x^2 + 16) - 32)]
</code></pre>
<p>If I need to numerically solve the equation, which I think I must do, how do I do it in Sage? </p>
http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=39235#post-id-39235Hello,
I tried a different way of doing the same. In the code below, eq1 is the circle and eq2 is the parabola. You'll find
the solution you are looking for.
x, y = var('x, y');
eq1 = x^2 + y^2 == 16; show(eq1);
eq2 = y == 1/4*x^2-1.28; show(eq2);
eqs = [eq1, eq2];
sol = solve(eqs, x, y); show(sol);
Hope this helped.Sat, 21 Oct 2017 04:09:42 -0500http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=39235#post-id-39235Answer by philipp7 for <p>Hello, </p>
<p>In truth, I am feeling like an idiot but it has been a long while since I have done math. </p>
<p>What I want to do is find the intersection points between a parabola and a circle. After I put both equations in x and set them equal, I have: </p>
<pre><code>var('y')
solve (sqrt(16-x^2) - 1/4*x^2-1.28==0, x)
</code></pre>
<p>Problem is, I get the following for answers: </p>
<pre><code>[x == -2/5*sqrt(25*sqrt(-x^2 + 16) - 32), x == 2/5*sqrt(25*sqrt(-x^2 + 16) - 32)]
</code></pre>
<p>If I need to numerically solve the equation, which I think I must do, how do I do it in Sage? </p>
http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=37985#post-id-37985Hello!
You can try the option to_poly_solve which gives you:
sage: eqn = sqrt(16-x^2) - (1/4)*x^2-1.28==0;
sage: sol = solve(eqn, x, to_poly_solve=true); sol
[x == -2/5*sqrt(2)*sqrt(5*sqrt(157) - 41), x == 2/5*sqrt(2)*sqrt(5*sqrt(157) - 41)]
sage: n(sol[0].rhs())
-2.63209850458274
sage: n(sol[1].rhs())
2.63209850458274
Another possiblity would be to plot the function for getting the number and estimate values for the solutions. Then you can try to find those solutions using find_roots:
sage: eqn.find_root(-3,-2)
-2.632098504582708
sage: eqn.find_root(2,3)
2.632098504582708
Kind regards
PhilippSat, 17 Jun 2017 04:17:02 -0500http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?answer=37985#post-id-37985Comment by happys5 for <p>Hello!</p>
<p>You can try the option to_poly_solve which gives you:</p>
<pre><code>sage: eqn = sqrt(16-x^2) - (1/4)*x^2-1.28==0;
sage: sol = solve(eqn, x, to_poly_solve=true); sol
[x == -2/5*sqrt(2)*sqrt(5*sqrt(157) - 41), x == 2/5*sqrt(2)*sqrt(5*sqrt(157) - 41)]
sage: n(sol[0].rhs())
-2.63209850458274
sage: n(sol[1].rhs())
2.63209850458274
</code></pre>
<p>Another possiblity would be to plot the function for getting the number and estimate values for the solutions. Then you can try to find those solutions using find_roots:</p>
<pre><code>sage: eqn.find_root(-3,-2)
-2.632098504582708
sage: eqn.find_root(2,3)
2.632098504582708
</code></pre>
<p>Kind regards</p>
<p>Philipp</p>
http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?comment=37988#post-id-37988Thanks, Philipp!Sat, 17 Jun 2017 13:37:01 -0500http://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/?comment=37988#post-id-37988