ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 29 Aug 2018 09:17:24 -0500Conflicting Sage vs Wolfram evaluation of a limit?http://ask.sagemath.org/question/43517/conflicting-sage-vs-wolfram-evaluation-of-a-limit/<s> >Why are the following computed limits different (1 by Sage, 0 by Wolfram), and which (if either) is correct?
</s>
**EDIT**: Increasing the numerical precision in Wolfram produces a plot that *strongly suggests* that the limit is indeed $0$, which it had already computed. Presumably, Sage is computing the wrong limit simply because of inadequate numerical precision, so the question is now ...
>How can I increase the numerical precision in Sage, so that `limit()` and `plot()` will produce the correct results (i.e., the limit should be $0$ and the plot should show a stable approach to $0$)?
**Sage**: (you can cut/paste/execute this code [here](http://sagecell.sagemath.org/))
#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a)
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); print(limit(V(a,w), a=oo))
plot(V(a,1),a,0,8)
#out()=
1 #<--------- computed limit = 1
[![enter image description here][1]][1]
**Wolfram**: (you can execute this code [here](https://sandbox.open.wolframcloud.com/app/objects/0e2860d3-6c86-4d61-a9cf-e97fcf88c3b5#sidebar=compute))
#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2
Assuming[w>0, Limit[V[a,w], a -> Infinity]]
Plot[V[a, 10], {a, 0, 100}, WorkingPrecision -> 128]
#out()=
0 (* <--------- computed limit = 0 *)
[![enter image description here][2]][2]
(This is supposed to compute the limit, as a -> oo, of the [variance of a standard normal distribution when truncated to the interval (a,a+w)](https://en.wikipedia.org/wiki/Truncated_normal_distribution#Moments).)
[1]: https://i.stack.imgur.com/eRAjI.png
[2]: https://i.stack.imgur.com/WTSf9.pngres0001Wed, 29 Aug 2018 09:17:24 -0500http://ask.sagemath.org/question/43517/Limits with dictionarieshttp://ask.sagemath.org/question/9301/limits-with-dictionaries/Suppose I have a dictionary that is the result of a `solve` command, for example, `D={n1:2}`
I also have an expression stored, for example, `expr1 = 3*n1^2`
In this example, I want to find the limit of `expr1` as `n1 -> 2`.
How can I do this given some expression and some dictionary in general?
I haven't figured it out with `sage_eval` yet.
(I know that if it were just substitution, I could use `expr1.subs_expr(D)` but I have cases where I believe I need to use limits instead of substitution.)
Thanks!ktkohl96Thu, 06 Sep 2012 06:12:00 -0500http://ask.sagemath.org/question/9301/Symbolic limit computationhttp://ask.sagemath.org/question/8839/symbolic-limit-computation/Suppose W(t) is a function of t, and h(t,z) is a function of t and z. Define X(t,z) as follows.
var('t,z')
W = function('W',t)
h = function('h',t,z)
X = 2*diff(h,z)(z=W)^2 / (h - h(z=W)) - 2 * diff(h,z) / (z - W)
Now, I want to compute the limit of X as z tends to W(t). I have tried the command
limit(X,z=W),
but this does not work. I guess a simpler example is the following.
var('dt')
limit((W(t=t+dt)-W)/dt,dt=0)
Sage does not give the "right" answer, namely the derivative of W.
Any suggestion/comment is welcome and appreciated.
CartoFri, 30 Mar 2012 14:39:44 -0500http://ask.sagemath.org/question/8839/