upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

Theta functions for q -> 1 #132

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be useful if Jacobi theta functions could be evaluated
(accurately) in the limit q -> 1, including returning the appropriate limit
at q = 1. This is needed for example to solve the heat equation for small
t. I believe there are series expansions that can be used for this, e.g.:

http://functions.wolfram.com/EllipticFunctions/EllipticTheta3/06/01/04/

Original issue reported on code.google.com by fredrik....@gmail.com on 24 Feb 2009 at 12:10

GoogleCodeExporter commented 9 years ago
For example, this script solves the heat equation with homogeneous Dirichlet BC 
on
[0,1] with given initial temperature distribution u0. Note that evaluation of 
u1 is
very slow. Can u(x,t) be made fast and correct for arbitrarily small t, and can 
it be
made to evaluate even for t = 0?

from mpmath import *
mp.dps = 5

#u0 = lambda x: sin(2*pi*x)**2
#u0 = lambda x: 1.73
u0 = lambda x: cos(x)

def theta(x,t):
    return jtheta(3,pi*x/2,exp(-pi**2*t))*0.5

def u(x,t):
    return quadgl(lambda r: (theta(x-r,t)-theta(x+r,t))*u0(x), [0,1])

u1 = lambda x: u(x,0.001)
u2 = lambda x: u(x,0.01)
u3 = lambda x: u(x,0.1)
u4 = lambda x: u(x,0.2)

plot([u0, u1, u2, u3, u4], [0, 1], points=100)

Original comment by fredrik....@gmail.com on 24 Feb 2009 at 12:32