TransWikia.com

Strange behaviour with EllipticTheta functions

Mathematica Asked on September 27, 2021

For some time I have been using EllipticTheta[3,-,-] functions, and to me it seems that Mathematica is really not handling them in the best way. Below are two of the instances I have faced so far, and I would appreciate any input to resolve these issues.

1. Plots

Here is a plot I have tried and it works well:

Plot3D[EllipticTheta[3, Pi/2  x, t], {x, 0, 2}, {t, 0, 1}]

enter image description here

I understand the peaks as the Theta function approaches a Dirac comb when t=1.

Then I try

Plot3D[EllipticTheta[3, Pi/2 x, E^(- Pi^2 t)],{x,0,2},{t,0,tmax}]

this is how it looks for tmax=1

enter image description here

by increasing tmax things start looking strange, and eventually the kernel seems to crash (from about tmax=4.5). This is how it looks for tmax=5

enter image description here

It becomes even worse for larger values of tmax. I don’t seem to understand what is causing the problem, and how choosing larger intervals for the plot messes up the part of the plot for smaller values of t which were looking fine with tmax=1.

2. Derivatives

I have read that derivatives of the Theta function with respect to its third argument are problematic as discussed here, but I do not understand the reason. The solution suggested in that post is to use the corresponding PDE, i.e.

Derivative[0,0,1][EllipticTheta][3,Pi/2 x,E^(-Pi^2 t)] = 
Derivative[0,2,0][EllipticTheta][3,Pi/2 x,E^(-Pi^2 t)]

So this means instead of Derivative[0,1,1][EllipticTheta][3,Pi/2 x,E^(-Pi^2 t)] it’s better to use Derivative[0,3,0][EllipticTheta][3,Pi/2 x,E^(-Pi^2 t)]. To check, I plot it

Plot3D[ Evaluate[
  Derivative[0, 3, 0][EllipticTheta][3, Pi/2 x, E^(-Pi^2 t)]], {x, 0, 
  2}, {t, 0, 1}]

enter image description here

Note that this is quite slow to generate.
Q: How to improve the speed?

In addition, I do not know if the values of these higher-order derivatives are something that I could trust.

Also, when I try increasing t to, say, {t,0,2} Mathematica v12.1 jumps out of the notebook. Note that I am actually trying to use these derivatives as part of an integrand (like here) and I’d want to avoid singularities/numerical instabilities even in the cost of (a bit of) accuracy. So maybe I should use a finite sum, instead of the infinite sum in the definition of EllipticTheta?

Here is another example, which (I think) should be identical to zero (adapted from this post)

Plot[ Evaluate[ 
  D[EllipticTheta[3, x, E^(-Pi^2 t)], {x, 3}] /. x -> 0], {t, 0, 1}]

enter image description here

(edit/update: flinty’s solution to define a WorkingPrecision resolves this latter one. I had assumed Mathematica does not need that for built-in functions)

Question

Is there a better way to deal with EllipticTheta in Mathematica? I tried implementing it as the direct summation it is defined through, and ran exactly to the same problems. So I guess Mathematica might be actually evaluating the sum when EllipticTheta is called, and maybe that is causing the problems (since it’ll run into exponentials with very large negative powers).

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP