Skip to content
Back to formatted view

Raw Message

Message-ID: <4620f44d94d18edcd39737ee9294f276@soc.soton.ac.uk>
Date: 2005-05-06T07:27:11Z
From: robin hankin
Subject: FAQ 7.31

Jacobi's theta functions crop up here and there in various branches of 
mathematics,
such as unimodular and elliptic functions.

They have Taylor expansions, but the powers increase as the square of 
n, as in

1 + z + z^4 + z^9 + z^16 + z^25 + . . .

so they converge very quickly, provided |z|<1

The following toy function shows how I'm implementing these objects.  I 
just add terms until
they make no difference:


f <- function(z, maxiter=10){
    out.old <- 1
    for(n in 1:maxiter){
      out.new <- out.old + z^(n*n)
      if(identical(out.new, out.old)){
        return(out.new)
      }
      out.old <- out.new
    }
    stop("not converged")
  }

[NB this is not a real theta function!  Real theta functions  are more 
complicated. f() just shows the issues]

I worry about the use of identical() here, because I am comparing two 
floats for equality
as discussed in FAQ 7.31.    Perhaps all.equal() would be better:

  all.equal(1e99,1e99+1e83, tol=.Machine$double.eps)


Does the List have any comments to make?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743