On Thu, Oct 1, 2015 at 12:39 PM, Thomas Judson <[email protected]> wrote:
> Does anyone have any idea what is going on with the following code?
>
> var('t')
> g = 9.8
> m = 80
> c = 1/(2*sqrt(3))
> f(x) = tanh(x)
> v(t) = sqrt(g*m/c)*f(sqrt(g*c/m)*t)
> T = 18.13
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=8)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=7)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=6)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=5)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=4)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=3)
> sum(v(t)*T/800 for t in srange(0,T,T/800)).n(digits=2)
> t
>
> 752.44705
> 752.4470
> 752.448
> 752.44
> 752.4
> 754.
> 710.
>
> Tom Judson

expr.n(digits=foo) does NOT mean: "compute expr to foo digits of
precision", which is maybe hard to do in general.  It means evaluate
all of the leaf nodes of expr to foo digits of precision, then
simplify the resulting tree... and return what you get.  There is
absolutely no guarantee that *any* of the digits of the result are
valid.   I don't think this behavior is documented -- I wish somebody
would document it with clear examples showing how the rounding errors
happen.

If you want to get a certain number of guaranteed correct digits when
computing a numerical approximation to an expression, using interval
arithmetic.  E.g., as in your example, but do:

alpha = sum(v(t)*T/800 for t in srange(0,T,T/800))
RealIntervalField(26)(alpha)

752.45?

This means that every digit except maybe the last is definitely correct.

https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2015-10-01-145150-N.sagews


William




>
>
>
>
> =========
> Thomas W. Judson, Associate Professor
> Department of Mathematics and Statistics
> Stephen F. Austin State University
> P.O. Box 13040-3040 SFA Station
> Nacogdoches, TX  75962
>
> OFFICE: 316 Math
> TEL: (936) 468-1704
> EMAIL: [email protected]
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to