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.Tue, 25 Dec 2012 01:10:26 -0600Solve contains wrong solutionhttp://ask.sagemath.org/question/9597/solve-contains-wrong-solution/Hello, I tried to following to find a maxima of a function:
var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
And the solution sage spits out are:
[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.
Why does it give me this solution or am I doing anything wrong?Sat, 01 Dec 2012 15:14:02 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/Comment by maweki for <p>Hello, I tried to following to find a maxima of a function:</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
</code></pre>
<p>And the solution sage spits out are:</p>
<pre><code>[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
</code></pre>
<p>I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.</p>
<p>Why does it give me this solution or am I doing anything wrong?</p>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?comment=18596#post-id-18596I know, that I could only solve for f'(x)==0 and filter for f''(x)<0 but solve shouldn't contain solutions like that, I think.Sat, 01 Dec 2012 22:16:16 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?comment=18596#post-id-18596Answer by kcrisman for <p>Hello, I tried to following to find a maxima of a function:</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
</code></pre>
<p>And the solution sage spits out are:</p>
<pre><code>[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
</code></pre>
<p>I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.</p>
<p>Why does it give me this solution or am I doing anything wrong?</p>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14342#post-id-14342This is a bug (?) in `to_poly_solve` in Maxima.
(%i1) load(to_poly_solver);
Loading maxima-grobner $Revision: 1.6 $ $Date: 2009-06-02 07:49:49 $
(%o1) /Applications/MathApps/Sage-5.4.1-OSX-64bit-10.6.app/Contents/Resources/\
sage/local/share/maxima/5.26.0/share/contrib/to_poly_solver.mac
(%i3) display2d:false;
(%o3) false
(%i4) to_poly_solve([2*(x-1)*%e^(t*x)+t*(x-1)^2*%e^(t*x)=0,4*t*(x-1)*%e^(t*x)+t^2*(x-1)^2*%e^(t*x)+2*%e^(t*x)>0],[x]);
(%o4) %union([x = 1,2 > 0],[x = (t-2)/t,
t^2-2*(t-2)*t-4*t+4*(t-2)+(t-2)^2+2 > 0])
The current Maxima has
(%o4) %union([x = 1,2 > 0],[x = (t-2)/t,
t^2-2*(t-2)*t-4*t+4*(t-2)+(t-2)^2+2 > 0])
which is basically the same issue. I've reported this upstream [here](http://https://sourceforge.net/p/maxima/bugs/2512/).Mon, 03 Dec 2012 06:53:01 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14342#post-id-14342Answer by achrzesz for <p>Hello, I tried to following to find a maxima of a function:</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
</code></pre>
<p>And the solution sage spits out are:</p>
<pre><code>[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
</code></pre>
<p>I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.</p>
<p>Why does it give me this solution or am I doing anything wrong?</p>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14338#post-id-14338Nevertheless Sage can solve your problem
var('t x');
f=(e^(x*t))*(x-1)^2;
df=diff(f,x).factor();df # first derivative
(x - 1)*(t*x - t + 2)*e^(t*x)
sol= solve(derivative(f,x)==0,x);sol
[x == (t - 2)/t, x == 1] # stationary points
ddf=diff(df,x) # second derivative
ddf.subs(sol[1])
2*e^t # f_x'' positive, local minimum for x=1
ddf.subs(sol[0]).expand()
-2*e^(t - 2) # f_x'' negative, local maximum for x=(t-2)/t, t nonzero
# if t=0 then f=(x-1)^2Sat, 01 Dec 2012 21:13:15 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14338#post-id-14338Comment by maweki for <p>Nevertheless Sage can solve your problem</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
df=diff(f,x).factor();df # first derivative
(x - 1)*(t*x - t + 2)*e^(t*x)
sol= solve(derivative(f,x)==0,x);sol
[x == (t - 2)/t, x == 1] # stationary points
ddf=diff(df,x) # second derivative
ddf.subs(sol[1])
2*e^t # f_x'' positive, local minimum for x=1
ddf.subs(sol[0]).expand()
-2*e^(t - 2) # f_x'' negative, local maximum for x=(t-2)/t, t nonzero
# if t=0 then f=(x-1)^2
</code></pre>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?comment=18597#post-id-18597surely there must be something slightly off with this solution because for x=1 y is always 0. Only the local maximum at (t - 2)/t changes.Sat, 01 Dec 2012 21:50:28 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?comment=18597#post-id-18597Answer by Emmanuel Charpentier for <p>Hello, I tried to following to find a maxima of a function:</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
</code></pre>
<p>And the solution sage spits out are:</p>
<pre><code>[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
</code></pre>
<p>I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.</p>
<p>Why does it give me this solution or am I doing anything wrong?</p>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14395#post-id-14395I beg to differ :
Maxima 5.28.0 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) load(to_poly_solve);
Loading maxima-grobner $Revision: 1.6 $ $Date: 2009-06-02 07:49:49 $
(%o1) /usr/share/maxima/5.28.0/share/to_poly_solve/to_poly_solve.mac
(%i2) display2d:false;
(%o2) false
(%i3) f(x,t):=(%e^(x*t))*(x-1)^2;
(%o3) f(x,t):=%e^(x*t)*(x-1)^2
(%i4) map(factor,%solve([factor(diff(f(x,t),x))=0,factor(diff(diff(f(x,t),x),x))<0],x));
(%o4) %union([x = 1,-2 > 0],[x = (t-2)/t,2 > 0])
which is correct.
Note that I load()ed to poly solve, *not* to_poly_solver ; according to a comment in the former source, the latter is obsolete.
HTH,
Emmanuel CharpentierTue, 25 Dec 2012 01:10:26 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14395#post-id-14395Answer by Mark for <p>Hello, I tried to following to find a maxima of a function:</p>
<pre><code>var('t x');
f=(e^(x*t))*(x-1)^2;
maxima = solve([derivative(f,x)==0, derivative(f,x,2)<0],x)
show(maxima);
</code></pre>
<p>And the solution sage spits out are:</p>
<pre><code>[
[x == 1, -2 > 0],
[x == (t - 2)/t, -(t - 2)^2 + 2*(t - 2)*t - t^2 + 6 > 0]
]
</code></pre>
<p>I understand that sage cannot evaluate the validity of the second solution but the first one surely is no solution at all.</p>
<p>Why does it give me this solution or am I doing anything wrong?</p>
http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14339#post-id-14339I would not agree with you that these solutions are 'wrong'. They are just presented in a very user unfriendly way. The 1st one, i.e.:
[x == 1, -2 > 0]
definitely **is** a solution - it just specifies a range of measure zero, since
sage: -2>0
False
so, it is not 'wrong' as you state - it is just 'totally useless' ;)
The other solution is also perfectly ok since
sage: bool(-(t - 2)^2 + 2*(t - 2)*t - t^2 + 6)
True
so, the solution you want is
x == (t - 2)/t
which I think is ok ..... **however** I would definetely agree with you that
In[1]:= f[x_, t_] = Exp[x t] (x - 1)^2;
In[2]:= Solve[{D[f[x, t], x] == 0 , D[f[x, t], {x, 2}] < 0, {x, t}]
Out[2]= {{t -> ConditionalExpression[-(2/(-1 + x)), (t | x) \[Element] Reals]}}
from a well known competitor **is far more user friendly**
Sun, 02 Dec 2012 00:46:07 -0600http://ask.sagemath.org/question/9597/solve-contains-wrong-solution/?answer=14339#post-id-14339