I can plot a function with variable values as large as I need in gnuplot 4.4:
gnuplot> t = 10000*365.25*24*3600
gnuplot> f(x) = alpha*delta*exp(-alpha*x)*(sin(omega*t-alpha*x)-cos(omega*t-alpha*x))
gnuplot> plot f(x)
But If I instead want to iterate over t using similar values as above, by using the `plot for’ command, I get segfaults or it doesn’t seem to end (I waited a long time and still no response):
tau = int(40000*365.25*24*3600)
step = int(10000*365.25*24*3600)
f(x,t) = alpha*delta*exp(-alpha*x)*(sin(omega*t-alpha*x)-cos(omega*t-alpha*x))
plot for [t=0:tau:step] f(x,t)
If I have tau = 1000, and step = 10 then there is no problem, so I’m assuming that the size of the iterables is the issue. Is there some way around this or am I doing something wrong?
Some more info following @mgilson’s answer:
My system is 64-bit, and python can handle some very large integers:
>>> import sys
>>> sys.maxint
9223372036854775807
>>> tau = int(40000*365.25*24*3600)
>>> print tau
1262304000000
While gnuplot cannot:
gnuplot> tau = int(40000*365.25*24*3600)
gnuplot> print tau
-2147483648
Here’s the plot file if you want to try it:
tau = int(40000*365.25*24*3600)
delta = 10
kappa = 1e-6
omega = 2*pi/tau # angular frequency
alpha = sqrt(omega/(2*kappa)) # a simplifying factor
# set the range of x and time, t
set xrange[0:3000]
step = int(10000*365.25*24*3600)
f(x,t) = alpha*delta*exp(-alpha*x)*(sin(omega*t-alpha*x)-cos(omega*t-alpha*x))
plot for [t=0:tau:step] f(x,t)
quickly putting some of this into the python interpreter:
Notice the
Lat the end of the integers? That means that these numbers overflowed the system’s maximum integer size which is:for my system. Python handles this gracefully by using a custom type (
long) which allows the integer to occupy an unlimited number of bytes. The way gnuplot handles this is that the overflow wraps around …Now you have negative numbers where you expected positive ones.
EDIT
It appears that gnuplot uses 4-byte integers no matter what python’s
sys.maxintis. On my ubuntu x86_64 machine, python’ssys.maxintis much larger than gnuplot’s integer can handle (which is still capped at2**31-1).