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.Sun, 25 Nov 2018 00:46:10 +0100finding solutions with exponential series expansionhttps://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/ Hi, I couldnt recall how to solve the following for t
0.111t = 1- e^(-0.3t) . (The ans is t=8).
Thank you in advance !!
MichThu, 22 Nov 2018 23:53:33 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/Answer by Emmanuel Charpentier for <p>Hi, I couldnt recall how to solve the following for t</p>
<p>0.111t = 1- e^(-0.3t) . (The ans is t=8).</p>
<p>Thank you in advance !!
Mich</p>
https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?answer=44396#post-id-44396The steps (and graphs !) of this solution are available in [Sagecell](https://sagecell.sagemath.org/?z=eJx9kEFuwyAQRfeVegfEaogwYpxlxQ6fwMuqjVwZJ0gORDBNrZw-40SuuuoGIf7Tmz9chwKSpBZjPg8xOVnCMEv1-tItzhpE3FED2IjwCY01-x0pzi4lJhLdYur3VwVyzv59nPMR1HoewnIZ0ggcenScjHGagNTbE5UehRNSe-S8dR5_c7EB7QMQvmX9nAk8aiDdtBqtUqae8g9M8VjjLbg9T-lxtdQ8X8Oq2TrJ_jlI9KiF3K7v9sOUU-WqaW348HfLv35eYYppPJTMLP8OY5rUHVBKWGQ=&lang=sage)
Let's see. We suppose for now that this equation is to solve in reals :
var("t", domain="real")
Ex=0.111*t-(1- e^(-0.3*t))
We note an "obvious" root :
Ex.subs(t=0)
0
Is there an explicit solution ?
Ex.log_expand().log().solve(t)
[t == 1000/111*(2*e^(3/10*t) - 1)*e^(-3/10*t)]
No such luck : this is an implicit solution, no more informative than the original equation. Let's try a numerical solution. What is the shape of the representative curve of this expression ? A curve with a minimum around about 3, null at 0 and about 8, decreasing below 3 and increasing above 3 (see Sagecell). What can we prove ?
The first derivative is
Ex.diff(t)
-0.300000000000000*e^(-0.300000000000000*t) + 0.111000000000000
An increasing curve, null about 3. Can we prove that ? The second derivative is
Ex.diff(t,2)
0.0900000000000000*e^(-0.300000000000000*t)
Yay ! This is strictly positive for all reals. Therefore, the zero we "see" on the first derivative at about 3 is the only one, and is
Ex.diff(t).solve(t)
[t == 10*log(1/37*100^(1/3)*37^(2/3))]
Ex.diff(t).solve(t)[0].rhs().n()
3.31417424447956
Now we have *proven* that Ex is decreasing before this zero and increasing after that. At the minimum, it is :
Ex.subs(t==Ex.diff(t).solve(t)[0].rhs()).n()
-0.262126658862769
Since it is negative at this point and not upward bound (exercise for the reader : *prove it !*), it has two roots, one (0) being already known. The graphs suggest that Ex is positive for t=10. Let's try to find a numerical solution :
Ex.find_root(0.1,10,t)
8.25101463236195
which is the sought answer.
Left to the reader : what are the *complex* roots (if any...) ? Fair warning : this one is *much* harder than the real case (bound to problems open since the XIXth century, and still not solved...).
**EDIT :** It turns out that Sympy can give us the non-trivial real root in symbolic form :
sage: import sympy
sage: sympy.solve(Ex, t)
[10*LambertW(-100*exp(-100/37)/37)/3 + 1000/111,
10*LambertW(-100*exp(-100/37)/37, -1)/3 + 1000/111]
The numerical values are as expected :
sage: [s.n() for s in sympy.solve(Ex, t)]
[8.25101463236202, 0.e-123]
This function is known to Sage, but the conversion is incorrect (loses the second argument)
sage: [s._sage_() for s in sympy.solve(Ex, t)]
[10/3*lambert_w(-100/37*e^(-100/37)) + 1000/111,
10/3*lambert_w(-100/37*e^(-100/37)) + 1000/111]
This is now [Trac#26752](https://trac.sagemath.org/ticket/26752)Fri, 23 Nov 2018 19:14:26 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?answer=44396#post-id-44396Comment by Mich for <p>The steps (and graphs !) of this solution are available in <a href="https://sagecell.sagemath.org/?z=eJx9kEFuwyAQRfeVegfEaogwYpxlxQ6fwMuqjVwZJ0gORDBNrZw-40SuuuoGIf7Tmz9chwKSpBZjPg8xOVnCMEv1-tItzhpE3FED2IjwCY01-x0pzi4lJhLdYur3VwVyzv59nPMR1HoewnIZ0ggcenScjHGagNTbE5UehRNSe-S8dR5_c7EB7QMQvmX9nAk8aiDdtBqtUqae8g9M8VjjLbg9T-lxtdQ8X8Oq2TrJ_jlI9KiF3K7v9sOUU-WqaW348HfLv35eYYppPJTMLP8OY5rUHVBKWGQ=&lang=sage">Sagecell</a></p>
<p>Let's see. We suppose for now that this equation is to solve in reals :</p>
<pre><code>var("t", domain="real")
Ex=0.111*t-(1- e^(-0.3*t))
</code></pre>
<p>We note an "obvious" root :</p>
<pre><code>Ex.subs(t=0)
0
</code></pre>
<p>Is there an explicit solution ?</p>
<pre><code>Ex.log_expand().log().solve(t)
[t == 1000/111*(2*e^(3/10*t) - 1)*e^(-3/10*t)]
</code></pre>
<p>No such luck : this is an implicit solution, no more informative than the original equation. Let's try a numerical solution. What is the shape of the representative curve of this expression ? A curve with a minimum around about 3, null at 0 and about 8, decreasing below 3 and increasing above 3 (see Sagecell). What can we prove ?</p>
<p>The first derivative is</p>
<pre><code>Ex.diff(t)
-0.300000000000000*e^(-0.300000000000000*t) + 0.111000000000000
</code></pre>
<p>An increasing curve, null about 3. Can we prove that ? The second derivative is</p>
<pre><code>Ex.diff(t,2)
0.0900000000000000*e^(-0.300000000000000*t)
</code></pre>
<p>Yay ! This is strictly positive for all reals. Therefore, the zero we "see" on the first derivative at about 3 is the only one, and is</p>
<pre><code>Ex.diff(t).solve(t)
[t == 10*log(1/37*100^(1/3)*37^(2/3))]
Ex.diff(t).solve(t)[0].rhs().n()
3.31417424447956
</code></pre>
<p>Now we have <em>proven</em> that Ex is decreasing before this zero and increasing after that. At the minimum, it is :</p>
<pre><code>Ex.subs(t==Ex.diff(t).solve(t)[0].rhs()).n()
-0.262126658862769
</code></pre>
<p>Since it is negative at this point and not upward bound (exercise for the reader : <em>prove it !</em>), it has two roots, one (0) being already known. The graphs suggest that Ex is positive for t=10. Let's try to find a numerical solution : </p>
<pre><code>Ex.find_root(0.1,10,t)
8.25101463236195
</code></pre>
<p>which is the sought answer.</p>
<p>Left to the reader : what are the <em>complex</em> roots (if any...) ? Fair warning : this one is <em>much</em> harder than the real case (bound to problems open since the XIXth century, and still not solved...).</p>
<p><strong>EDIT :</strong> It turns out that Sympy can give us the non-trivial real root in symbolic form :</p>
<pre><code>sage: import sympy
sage: sympy.solve(Ex, t)
[10*LambertW(-100*exp(-100/37)/37)/3 + 1000/111,
10*LambertW(-100*exp(-100/37)/37, -1)/3 + 1000/111]
</code></pre>
<p>The numerical values are as expected :</p>
<pre><code>sage: [s.n() for s in sympy.solve(Ex, t)]
[8.25101463236202, 0.e-123]
</code></pre>
<p>This function is known to Sage, but the conversion is incorrect (loses the second argument)</p>
<pre><code>sage: [s._sage_() for s in sympy.solve(Ex, t)]
[10/3*lambert_w(-100/37*e^(-100/37)) + 1000/111,
10/3*lambert_w(-100/37*e^(-100/37)) + 1000/111]
</code></pre>
<p>This is now <a href="https://trac.sagemath.org/ticket/26752">Trac#26752</a></p>
https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44425#post-id-44425Thank you for your help!! ( I m still surprised that the eqn. looks simple, but yet it can be tricky to solve. But appreciate your help !)Sun, 25 Nov 2018 00:46:10 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44425#post-id-44425Answer by slelievre for <p>Hi, I couldnt recall how to solve the following for t</p>
<p>0.111t = 1- e^(-0.3t) . (The ans is t=8).</p>
<p>Thank you in advance !!
Mich</p>
https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?answer=44402#post-id-44402The value `8` is not a solution, but there is a solution
whose approximate solution is 8.2510146...
Here are some ways to work on solving this equation.
Define `t` as a symbolic variable in the symbolic ring,
and call `eq` the equation.
sage: t = SR.var('t')
sage: eq = 0.111*t == 1-exp(-0.3*t)
Try to solve with `solve`: unfortunately, Sage returns an
equation which is equivalent to the equation we started with.
sage: solve(eq, t)
[t == 1000/111*(e^(3/10*t) - 1)*e^(-3/10*t)]
Use `find_root` to find an approximate solution between 5 and 10.
sage: eq.find_root(5, 10)
8.251014632362164
or
sage: find_root(eq, 5, 10)
8.251014632362164
The computation above is done using floating-point computations
and it is not clear which digits are exact.
For a computation using arbitrary precision, use the `mpmath` library:
define a function equal to the difference of the left-hand side and
the right-hand side of `eq` and use `mpmath.findroot` to look for a
root near 8:
sage: import mpmath
sage: mpmath.findroot(lambda t: 1 - exp(-0.3*t) - 0.111*t, 8)
mpf('8.2510146323620207')
See the answer by @Emmanuel Charpentier for how to use SymPy to get
an exact solution in symbolic form. It is likely Giac or FriCAS could
do it too.
Sat, 24 Nov 2018 00:44:26 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?answer=44402#post-id-44402Comment by Emmanuel Charpentier for <p>The value <code>8</code> is not a solution, but there is a solution
whose approximate solution is 8.2510146...</p>
<p>Here are some ways to work on solving this equation.</p>
<p>Define <code>t</code> as a symbolic variable in the symbolic ring,
and call <code>eq</code> the equation.</p>
<pre><code>sage: t = SR.var('t')
sage: eq = 0.111*t == 1-exp(-0.3*t)
</code></pre>
<p>Try to solve with <code>solve</code>: unfortunately, Sage returns an
equation which is equivalent to the equation we started with.</p>
<pre><code>sage: solve(eq, t)
[t == 1000/111*(e^(3/10*t) - 1)*e^(-3/10*t)]
</code></pre>
<p>Use <code>find_root</code> to find an approximate solution between 5 and 10.</p>
<pre><code>sage: eq.find_root(5, 10)
8.251014632362164
</code></pre>
<p>or</p>
<pre><code>sage: find_root(eq, 5, 10)
8.251014632362164
</code></pre>
<p>The computation above is done using floating-point computations
and it is not clear which digits are exact.</p>
<p>For a computation using arbitrary precision, use the <code>mpmath</code> library:
define a function equal to the difference of the left-hand side and
the right-hand side of <code>eq</code> and use <code>mpmath.findroot</code> to look for a
root near 8:</p>
<pre><code>sage: import mpmath
sage: mpmath.findroot(lambda t: 1 - exp(-0.3*t) - 0.111*t, 8)
mpf('8.2510146323620207')
</code></pre>
<p>See the answer by <a href="/users/1336/emmanuel-charpentier/">@Emmanuel Charpentier</a> for how to use SymPy to get
an exact solution in symbolic form. It is likely Giac or FriCAS could
do it too.</p>
https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44422#post-id-44422Neither Fricas nor Giac can solve this symbolically :
sage: giac("solve(111*t/1000-(1-exp(-3*t/10)),t)")
list[-6.76523232004e-14,8.25101463236]
sage: fricas("solve(111*t/1000-(1-exp(-3*t/10)),t)")
[]
Mathematica gives an answer subsuming Sympy's and asserting the existence of an infinity of (complex) solutions :
sage: mathematica("Reduce[111*t/1000==1-Exp[-3*t/10],t]")
(Element[C[1], Integers] &&
t == 1000/111 + (10*ProductLog[C[1], -100/(37*E^(100/37))])/3) || t == 0
(Reformatted from Mathematica's help) :
ProductLog][z]
gives the principal solution for w in z == w e^w.
ProductLog[k,z]
gives the k^th solution.
From Sage's `lambert_w?` :
This function satisfies the equation
z = W_n(z) e^{W_n(z)}
Same difference...Sat, 24 Nov 2018 20:26:11 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44422#post-id-44422Comment by Mich for <p>The value <code>8</code> is not a solution, but there is a solution
whose approximate solution is 8.2510146...</p>
<p>Here are some ways to work on solving this equation.</p>
<p>Define <code>t</code> as a symbolic variable in the symbolic ring,
and call <code>eq</code> the equation.</p>
<pre><code>sage: t = SR.var('t')
sage: eq = 0.111*t == 1-exp(-0.3*t)
</code></pre>
<p>Try to solve with <code>solve</code>: unfortunately, Sage returns an
equation which is equivalent to the equation we started with.</p>
<pre><code>sage: solve(eq, t)
[t == 1000/111*(e^(3/10*t) - 1)*e^(-3/10*t)]
</code></pre>
<p>Use <code>find_root</code> to find an approximate solution between 5 and 10.</p>
<pre><code>sage: eq.find_root(5, 10)
8.251014632362164
</code></pre>
<p>or</p>
<pre><code>sage: find_root(eq, 5, 10)
8.251014632362164
</code></pre>
<p>The computation above is done using floating-point computations
and it is not clear which digits are exact.</p>
<p>For a computation using arbitrary precision, use the <code>mpmath</code> library:
define a function equal to the difference of the left-hand side and
the right-hand side of <code>eq</code> and use <code>mpmath.findroot</code> to look for a
root near 8:</p>
<pre><code>sage: import mpmath
sage: mpmath.findroot(lambda t: 1 - exp(-0.3*t) - 0.111*t, 8)
mpf('8.2510146323620207')
</code></pre>
<p>See the answer by <a href="/users/1336/emmanuel-charpentier/">@Emmanuel Charpentier</a> for how to use SymPy to get
an exact solution in symbolic form. It is likely Giac or FriCAS could
do it too.</p>
https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44424#post-id-44424Thank you for your help!! ( I m still surprised that the eqn. looks simple, but yet it can be tricky to solve. But appreciate your help !)Sun, 25 Nov 2018 00:45:51 +0100https://ask.sagemath.org/question/44389/finding-solutions-with-exponential-series-expansion/?comment=44424#post-id-44424