ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 26 May 2012 02:13:39 -0500Simplify exponentialshttps://ask.sagemath.org/question/9002/simplify-exponentials/I'm using Sage to check the initial condition for a solution to the advection-diffusion equation. Here the initial condition is checked using a limit whose result should be zero. But, Sage gives the difference of two equivalent exponentials and leaves it without simplifying to zero. These exponentials only differ in that one has a 1/10 in it and one has a 0.1.
Here is the code:
var('u,x,t')
erfc(x) = 1-erf(x)
k=0.03
D=0.3
C=2.
u(x,t) = C*1/2*(erfc((x-k*t)/sqrt(4*D*t))+exp(x*k/D)*erfc((x+k*t)/sqrt(4*D*t)))
assume(x>0)
ans=limit(u(x,t),t=0,dir='+')
print ans.simplify_full()
The result is:
-e^(1/10*x) + e^(0.1*x)
Any advice on how to get this to simplify to zero?
Fri, 25 May 2012 10:17:51 -0500https://ask.sagemath.org/question/9002/simplify-exponentials/Answer by ndomes for <p>I'm using Sage to check the initial condition for a solution to the advection-diffusion equation. Here the initial condition is checked using a limit whose result should be zero. But, Sage gives the difference of two equivalent exponentials and leaves it without simplifying to zero. These exponentials only differ in that one has a 1/10 in it and one has a 0.1.</p>
<p>Here is the code:</p>
<pre><code>var('u,x,t')
erfc(x) = 1-erf(x)
k=0.03
D=0.3
C=2.
u(x,t) = C*1/2*(erfc((x-k*t)/sqrt(4*D*t))+exp(x*k/D)*erfc((x+k*t)/sqrt(4*D*t)))
assume(x>0)
ans=limit(u(x,t),t=0,dir='+')
print ans.simplify_full()
</code></pre>
<p>The result is:</p>
<pre><code>-e^(1/10*x) + e^(0.1*x)
</code></pre>
<p>Any advice on how to get this to simplify to zero?</p>
https://ask.sagemath.org/question/9002/simplify-exponentials/?answer=13614#post-id-13614What's about this version:
var('u,x,t')
erfc(x) = 1-erf(x)
k=3/100
D=3/10
C=2
u(x,t) = C*1/2*(erfc((x-k*t)/sqrt(4*D*t))+exp(x*k/D)*erfc((x+k*t)/sqrt(4*D*t)))
assume(x>0)
ans=limit(u(x,t),t=0,dir='+')
print ans.simplify_full()Fri, 25 May 2012 10:46:42 -0500https://ask.sagemath.org/question/9002/simplify-exponentials/?answer=13614#post-id-13614Comment by calc314 for <p>What's about this version:</p>
<pre><code>var('u,x,t')
erfc(x) = 1-erf(x)
k=3/100
D=3/10
C=2
u(x,t) = C*1/2*(erfc((x-k*t)/sqrt(4*D*t))+exp(x*k/D)*erfc((x+k*t)/sqrt(4*D*t)))
assume(x>0)
ans=limit(u(x,t),t=0,dir='+')
print ans.simplify_full()
</code></pre>
https://ask.sagemath.org/question/9002/simplify-exponentials/?comment=19737#post-id-19737That certainly works, even without calling simplify_full. But, why is it that we cannot mix rationals and floats? Moreover, when I just type in "-e^(1/10*x) + e^(0.1*x)", Sage computes the result to be zero. So, why does Sage simplify this automatically sometimes and sometimes not?Sat, 26 May 2012 02:13:39 -0500https://ask.sagemath.org/question/9002/simplify-exponentials/?comment=19737#post-id-19737