In [1]:
using PiMath
using Gadfly

Some simple math


In [2]:
x=pi+2pi


Out[2]:

In [3]:
x/3


Out[3]:
1.0π

Type promotion should work as expected


In [4]:
x-(4//3)*pi


Out[4]:
5π/3

In [5]:
x+1


Out[5]:
10.42477796076938

In [6]:
y=2pi
x/y


Out[6]:
1.5

Exact results for sin and cosine of integer multiples of pi


In [7]:
(sin(2pi),cos(2pi))


Out[7]:
(0.0,1.0)

We can define Ranges


In [8]:
range1=linspace(0,4pi,100)


Out[8]:
0.0π:0.04040404040404041π:4.0π

And we get nice axes labels


In [9]:
y=sin(range1);
plot(x=range1,y=y)


Out[9]:
x -5.0π -4.0π -3.0π -2.0π -1.0π 0.0π 1.0π 2.0π 3.0π 4.0π 5.0π 6.0π 7.000000000000001π 8.0π 9.0π -4.0π -3.8000000000000003π -3.6π -3.400000000000001π -3.1999999999999997π -3.0π -2.8000000000000003π -2.6π -2.4000000000000004π -2.2π -2.0π -1.8π -1.5999999999999999π -1.4000000000000001π -1.2000000000000002π -1.0π -0.7999999999999999π -0.6000000000000001π -0.39999999999999997π -0.19999999999999998π 0.0π 0.19999999999999998π 0.39999999999999997π 0.6000000000000001π 0.7999999999999999π 1.0π 1.2000000000000002π 1.4000000000000001π 1.5999999999999999π 1.8π 2.0π 2.2π 2.4000000000000004π 2.6π 2.8000000000000003π 3.0π 3.1999999999999997π 3.400000000000001π 3.6π 3.8000000000000003π 4.0π 4.2π 4.4π 4.6000000000000005π 4.800000000000001π 5.0π 5.2π 5.4π 5.6000000000000005π 5.800000000000001π 6.0π 6.2π 6.3999999999999995π 6.6000000000000005π 6.800000000000002π 7.000000000000001π 7.2π 7.4π 7.6000000000000005π 7.800000000000001π 8.0π -5.0π 0.0π 5.0π 10.0π -4.0π -3.5000000000000004π -3.0π -2.5π -2.0π -1.5π -1.0π -0.5π 0.0π 0.5π 1.0π 1.5π 2.0π 2.5π 3.0π 3.5000000000000004π 4.0π 4.5π 5.0π 5.5π 6.0π 6.499999999999999π 7.000000000000001π 7.5π 8.0π -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 -4 -2 0 2 4 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 y

Same for arrays


In [10]:
pirange2=[x*pi for x=0:0.02:1]
plot(x=pirange2,y=cos(pirange2.*3))


Out[10]:
x -1.5π -1.0π -0.5π 0.0π 0.5π 1.0π 1.5π 2.0π 2.5π -1.0π -0.9500000000000001π -0.9π -0.8500000000000002π -0.7999999999999999π -0.75π -0.7000000000000001π -0.65π -0.6000000000000001π -0.55π -0.5π -0.45π -0.39999999999999997π -0.35000000000000003π -0.30000000000000004π -0.25π -0.19999999999999998π -0.15000000000000002π -0.09999999999999999π -0.049999999999999996π 0.0π 0.049999999999999996π 0.09999999999999999π 0.15000000000000002π 0.19999999999999998π 0.25π 0.30000000000000004π 0.35000000000000003π 0.39999999999999997π 0.45π 0.5π 0.55π 0.6000000000000001π 0.65π 0.7000000000000001π 0.75π 0.7999999999999999π 0.8500000000000002π 0.9π 0.9500000000000001π 1.0π 1.05π 1.1π 1.1500000000000001π 1.2000000000000002π 1.25π 1.3π 1.35π 1.4000000000000001π 1.4500000000000002π 1.5π 1.55π 1.5999999999999999π 1.6500000000000001π 1.7000000000000004π 1.7500000000000002π 1.8π 1.85π 1.9000000000000001π 1.9500000000000002π 2.0π -1.0π 0.0π 1.0π 2.0π -1.0π -0.9π -0.7999999999999999π -0.7000000000000001π -0.6000000000000001π -0.5π -0.39999999999999997π -0.30000000000000004π -0.19999999999999998π -0.09999999999999999π 0.0π 0.09999999999999999π 0.19999999999999998π 0.30000000000000004π 0.39999999999999997π 0.5π 0.6000000000000001π 0.7000000000000001π 0.7999999999999999π 0.9π 1.0π 1.1π 1.2000000000000002π 1.3π 1.4000000000000001π 1.5π 1.5999999999999999π 1.7000000000000004π 1.8π 1.9000000000000001π 2.0π -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 -4 -2 0 2 4 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 y