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.Mon, 21 Feb 2011 11:24:45 +0100Unexpected solve() resulthttps://ask.sagemath.org/question/7959/unexpected-solve-result/Hi,
Let
$\hspace{1in} f(x) = -\frac{1}{2} x + \sqrt{x^{2} + 25} + 4 $
I would like to find the first derivative of f(x) and then the value of x when $f'(x)=0 $.
This is what I did:
f(x)=(x^2+25)^(1/2)+(1/2)*(8-x)
ans=f(x).diff(x)==0
print ans.solve(x)
But that gives the answer:
$\hspace{1in} x = \frac{1}{2} \sqrt{x^{2} + 25} $
I had to change the last line to:
print ((ans.solve(x)[0]*2)^2).solve(x)
To give the correct answer:
$ \hspace{1in} x = -\frac{5}{3}\sqrt{3}, x = \frac{5}{3}\sqrt{3} $
Why do I have to do that?Sun, 20 Feb 2011 09:35:47 +0100https://ask.sagemath.org/question/7959/unexpected-solve-result/Answer by kcrisman for <p>Hi,</p>
<p>Let </p>
<p>$\hspace{1in} f(x) = -\frac{1}{2} x + \sqrt{x^{2} + 25} + 4 $</p>
<p>I would like to find the first derivative of f(x) and then the value of x when $f'(x)=0 $.</p>
<p>This is what I did:</p>
<pre><code>f(x)=(x^2+25)^(1/2)+(1/2)*(8-x)
ans=f(x).diff(x)==0
print ans.solve(x)
</code></pre>
<p>But that gives the answer:</p>
<p>$\hspace{1in} x = \frac{1}{2} \sqrt{x^{2} + 25} $</p>
<p>I had to change the last line to:</p>
<pre><code>print ((ans.solve(x)[0]*2)^2).solve(x)
</code></pre>
<p>To give the correct answer:</p>
<p>$ \hspace{1in} x = -\frac{5}{3}\sqrt{3}, x = \frac{5}{3}\sqrt{3} $</p>
<p>Why do I have to do that?</p>
https://ask.sagemath.org/question/7959/unexpected-solve-result/?answer=12133#post-id-12133Try
sage: ans.solve(x,to_poly_solve=True)
[x == 5/3*sqrt(3)]
Another reminder to make sure that the global `solve?` has the same information about this option as the local `x.solve?`. Though in this case,
sage: ans.solve?
would give you information about this option.
Mon, 21 Feb 2011 11:24:45 +0100https://ask.sagemath.org/question/7959/unexpected-solve-result/?answer=12133#post-id-12133