A little plot for one of my friends, code:
a <- 1:360 b <- 1:360 AB <- outer(-sign(cos(pi * a / 180)), sign(cos(pi * b / 180)), "*") d <- outer(a, b, "-") ABvec <- as.vector(AB) dvec <- as.vector(d) out <- aggregate(x = ABvec, by = list(dvec), FUN = mean) str(out) dvals <- out[ , 1] corrs <- out[ , 2] plot(dvals, corrs, type = "l") lines(dvals, -cos(pi * dvals / 180), col = “magenta”)
'data.frame': 719 obs. of 2 variables: $ Group.1: int -359 -358 -357 -356 -355 -354 -353 -352 -351 -350 … $ x : num -1 -1 -0.999 -0.998 -0.997 …
You can see the context of this R programming exercise, here:
Take two large wooden disks and colour half of each black, half white. Fix to a wall. There’s a pointer painted on the disks, near the edge, in the middle of the black half of the circumference. Painted on the wall, just above the top of each disk, is another pointer. Around the side of the disk, painted on the wall, equally spaced, are the numbers 1 to 360; 360 on top. Spin each disk. Wait till it stops. The pointers painted in the disks each point to a number alpha, beta between 1 and 360, painted on the wall. The pointers at the top of the disk painted on the wall point either to black, or to white, in the disk. That defines A = +/- 1 and B = +/- 1. You repeat this fairground game many, many times, and average A times B for each value of delta = alpha – beta.
Image: two fairground “wheels of fortune” which have come to rest at A = +1 (black on top), B = -1 (white on top), alpha = 40 (approx), beta = 170 (approx)
The earlier drawn graph is, I believe, piecewise quadratic.