Friday, June 24, 2016

more Chladni figures in R

Following on from an earlier post, the Chladni images here are made using a slightly modified version of the same R script (source here), which uses cosines instead of sines. If you imagine the square of the vibrating surface to be fixed at the center (as depicted below), using cosines seems the natural choice. When modeling standing waves, cosines are used to model open-ended pipes, while sines are used to model fixed-end strings.


Playing around with cosine-based formulas led to some images that seemed very close to Chadni's own diagrams, which can be found in an appendix to his book on Google books.

For a few of these I've uploaded the scripts that produced them.

Chladni image 40 b

 Chladni image 41

Chladni image 53

Chladni image 58

Chladni image 63

Source for these can be found on github: https://github.com/dmackinnon1/r_examples
And of course, many more are possible. Try a few yourself :)

Rascal Triangle


A few early iterations of something produced by a short script in R. What is it? You may see it more clearly in some of its later stages of development.


Yes, it is Pascal's Triangle modulo 2 - I knew you would recognize it :). The R source for generating these images is here. Like other recent posts, this is another example of using R in some simple programming exercises, pretty much completely unrelated to its intended purpose as a language for statistical computing. A wile back, there was a post about using TinkerPlots, a data management software tool for young folk, to do something similar (more detailed instructions on drawing a general Pascal Triangle in TinkerPlots can be found in this article),



Wednesday, June 15, 2016

chladni-esque figures in R

some Chladni-esque figures

Continuing on from this post, I am playing around with some unusual R language programming activities by creating some simplified Chladni figures.

Named for Ernst Chladni, these figures represent nodal patterns formed by vibrating surfaces. Traditionally, these are formed placing fine particles on a surface, like a sheet of metal that is set vibrating (a violin bow against an edge of the metal plate is one popular method). The particles settle in the areas of the surface that have the least motion - the nodes. When you achieve a resonant frequency, a characteristic pattern emerges. 

some more Chladni-esque figures

Chladni was not the first to study these, but his text is an early systematic treatment (several French and German versions are on Google Books, the German text has the best figures, in an appendix). A more recent contributor, Mary Desiree Waller, published a book Chladni Figures, a Study in Symmetry in 1961, which I would love to get a look at someday. In the 1970s, Chilandi figures were sucked down the rabbithole of Cymatics, and seem now seem to appeal equally to students of actual physics and metaphysics. It is probably fitting that these figures are embraced by romantics as much (or more) as they are by scientists. Chladni's study appeared at the end of the Enlightenment, almost at the beginning of the 19th century, and I imagine his demonstrations occurring in parlors similar to those where seances were held. The mysterious formation of these figures must have seemed to some as the manifestation of a hidden world.  

Chladni's sketches of some nodal patterns on a vibrating surface
Why use R for this? My motivation was not to select the best tool for exploring this topic, but to learn a bit more about programming in R. It was also not to try and produce exact Chladni figures, but something that reasonably resembled them. It turns out that R isn't such an unreasonable choice for this particular programming exercise, if you consider how easy it turns out to be to generate the figures using R. As an educational exercise, it makes some instructive use of R's vectorized methods, for loops, and the image function.On the other hand, we are not going to use any of R's statistical functions, so in some respects R remains an unusual (or maybe even bizarre) choice for this.


In any case, we can create simple Chladni-esque figures by thinking of a rectangular metal plate as a matrix in R (each cell being a point on the metal plate).Each entry in the matrix will receive values that represent the displacement of the plate at those coordinates at some snapshot in time.The matrix is plotted using R's image function, using a grey color range (try experimenting with other color ranges, or with the contour function).

The source code is here.

The idea is that a vibrating square surface whose edges are fixed (not moving) can be modeled as a product sine waves - one going in the horizontal direction, the other going in the vertical direction. Essentially, the displacement caused by a standing wave at a point x,y on the square is modeled as sin(kfx)*sin(kfy), where f is pi/2L, L being the length of the side of the square. and k is an integer. If k = 1, we get the 'fundamental' wave (first harmonic) for the square surface, and if k = 2 we get the first overtone (second harmonic). If we plot each wave separately we end up with a grid that gets finer and finer as we increase k values. However, things get more interesting if we form the sum of different harmonics. The images below show what we get forming the image for waves with = 1 and k = 2 separately, and then what we get when we sum them together.

fundamental, first overtone, and both together
Including or excluding overtones gives a wide variety of images, and if you increase the amplitude of particular overtones (by multiplying the corresponding term by some integer greater than 1), you can get even more patterns, some of which bear a striking resemblance to Chladni's original hand-drawn figures.




See this post for some additional chladni figures.