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.Fri, 13 Apr 2018 08:06:25 +0200Strange Solutionshttps://ask.sagemath.org/question/41996/strange-solutions/Sometimes the solutions given by Sage are weird. For example, the
equation below has only one solution, yet sage gives this output.
sage: solve(0.1*1==1*e^(-0.38*t),t)
[t == 50*log(10^(1/19)*e^(2/19*I*pi)),
t == 50*log(10^(1/19)*e^(4/19*I*pi)),
t == 50*log(10^(1/19)*e^(6/19*I*pi)),
t == 50*log(10^(1/19)*e^(8/19*I*pi)),
t == 50*log(10^(1/19)*e^(10/19*I*pi)),
t == 50*log(10^(1/19)*e^(12/19*I*pi)),
t == 50*log(10^(1/19)*e^(14/19*I*pi)),
t == 50*log(10^(1/19)*e^(16/19*I*pi)),
t == 50*log(10^(1/19)*e^(18/19*I*pi)),
t == -900/19*I*pi + 50/19*log(10),
t == -800/19*I*pi + 50/19*log(10),
t == -700/19*I*pi + 50/19*log(10),
t == -600/19*I*pi + 50/19*log(10),
t == -500/19*I*pi + 50/19*log(10),
t == -400/19*I*pi + 50/19*log(10),
t == -300/19*I*pi + 50/19*log(10),
t == -200/19*I*pi + 50/19*log(10),
t == -100/19*I*pi + 50/19*log(10),
t == 50/19*log(10)]Thu, 12 Apr 2018 21:21:12 +0200https://ask.sagemath.org/question/41996/strange-solutions/Answer by Emmanuel Charpentier for <p>Sometimes the solutions given by Sage are weird. For example, the
equation below has only one solution, yet sage gives this output.</p>
<pre><code>sage: solve(0.1*1==1*e^(-0.38*t),t)
[t == 50*log(10^(1/19)*e^(2/19*I*pi)),
t == 50*log(10^(1/19)*e^(4/19*I*pi)),
t == 50*log(10^(1/19)*e^(6/19*I*pi)),
t == 50*log(10^(1/19)*e^(8/19*I*pi)),
t == 50*log(10^(1/19)*e^(10/19*I*pi)),
t == 50*log(10^(1/19)*e^(12/19*I*pi)),
t == 50*log(10^(1/19)*e^(14/19*I*pi)),
t == 50*log(10^(1/19)*e^(16/19*I*pi)),
t == 50*log(10^(1/19)*e^(18/19*I*pi)),
t == -900/19*I*pi + 50/19*log(10),
t == -800/19*I*pi + 50/19*log(10),
t == -700/19*I*pi + 50/19*log(10),
t == -600/19*I*pi + 50/19*log(10),
t == -500/19*I*pi + 50/19*log(10),
t == -400/19*I*pi + 50/19*log(10),
t == -300/19*I*pi + 50/19*log(10),
t == -200/19*I*pi + 50/19*log(10),
t == -100/19*I*pi + 50/19*log(10),
t == 50/19*log(10)]
</code></pre>
https://ask.sagemath.org/question/41996/strange-solutions/?answer=41998#post-id-41998[ This smells homework. Therefore, some hints... ]
Ahem ! Your equation has, indeed one *real* solution... and 18 *complex* solutions. Its structure will become more transparent if you accept to replace its float coefficient by exact numbers and solve it symbolically...
The numerical values should also give you some hints :
sage: [(E.subs(s).rhs()-E.subs(s).lhs()).n().abs() for s in solve(0.1*1==1*e^(-0.38*t),t)]
[8.88516071398867e-16,
8.97447312850170e-16,
7.34788079488409e-17,
8.93565536393413e-16,
8.96581565195064e-16,
9.00254100846723e-16,
9.04575147216186e-16,
9.09535461462144e-16,
9.15124648438264e-16,
2.22176931601818e-16,
1.97899526057791e-16,
5.39806219580408e-16,
1.49555718205910e-16,
1.25570576985110e-16,
1.01827474616583e-16,
7.85462105727423e-17,
5.63026431885206e-17,
3.70172377524261e-17,
2.77555756156289e-17]
**EDIT** to answer your further question : another way to solve this is, as I told already, to use an exact ring, i. e. replace 0.1 by 1/10 and 0.38 by 38/100 (or 19/50, according to your tastes), so you will work with rationals (which have an exact representation in Sage) in place of "floats", which are limited-precision approximations).
Your problem becomes :
sage: var("t")
t
sage: E=1/10-1*e^(-38/100*t) ## Left-hand - right-hand
sage: S=solve(1/10-1*e^(-38/100*t),t) ## (Exact) solutions
## Check by substitution that all the proposed solutions are indeed solutions.
sage: [E.subs(s).trig_expand().expand() for s in S]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
And your real solution is :
sage: [s for s in S if s.rhs().is_real()]
[t == 50/19*log(10)]
Clearer ?
*And yes, I've made your homework for you. Shame on me...*Fri, 13 Apr 2018 07:57:04 +0200https://ask.sagemath.org/question/41996/strange-solutions/?answer=41998#post-id-41998Comment by o6p for <p>[ This smells homework. Therefore, some hints... ]</p>
<p>Ahem ! Your equation has, indeed one <em>real</em> solution... and 18 <em>complex</em> solutions. Its structure will become more transparent if you accept to replace its float coefficient by exact numbers and solve it symbolically...</p>
<p>The numerical values should also give you some hints :</p>
<pre><code>sage: [(E.subs(s).rhs()-E.subs(s).lhs()).n().abs() for s in solve(0.1*1==1*e^(-0.38*t),t)]
[8.88516071398867e-16,
8.97447312850170e-16,
7.34788079488409e-17,
8.93565536393413e-16,
8.96581565195064e-16,
9.00254100846723e-16,
9.04575147216186e-16,
9.09535461462144e-16,
9.15124648438264e-16,
2.22176931601818e-16,
1.97899526057791e-16,
5.39806219580408e-16,
1.49555718205910e-16,
1.25570576985110e-16,
1.01827474616583e-16,
7.85462105727423e-17,
5.63026431885206e-17,
3.70172377524261e-17,
2.77555756156289e-17]
</code></pre>
<p><strong>EDIT</strong> to answer your further question : another way to solve this is, as I told already, to use an exact ring, i. e. replace 0.1 by 1/10 and 0.38 by 38/100 (or 19/50, according to your tastes), so you will work with rationals (which have an exact representation in Sage) in place of "floats", which are limited-precision approximations).</p>
<p>Your problem becomes :</p>
<pre><code>sage: var("t")
t
sage: E=1/10-1*e^(-38/100*t) ## Left-hand - right-hand
sage: S=solve(1/10-1*e^(-38/100*t),t) ## (Exact) solutions
## Check by substitution that all the proposed solutions are indeed solutions.
sage: [E.subs(s).trig_expand().expand() for s in S]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
</code></pre>
<p>And your real solution is :</p>
<pre><code>sage: [s for s in S if s.rhs().is_real()]
[t == 50/19*log(10)]
</code></pre>
<p>Clearer ?</p>
<p><em>And yes, I've made your homework for you. Shame on me...</em></p>
https://ask.sagemath.org/question/41996/strange-solutions/?comment=41999#post-id-41999Thanks for the answer. Is there a function to display the real solution only?Fri, 13 Apr 2018 08:06:25 +0200https://ask.sagemath.org/question/41996/strange-solutions/?comment=41999#post-id-41999