Article 593YA Playing around with a rational rose

Playing around with a rational rose

by
John
from John D. Cook on (#593YA)

A rose" in mathematics is typically a curve with polar equation

r = cos(k)

where k is a positive integer. If k is odd, the resulting graph has k petals" and if k is even, the plot has 2k petals.

Sometimes the term rose is generalized to the case of non-integer k. This is the sense in which I'm using the phrase rational rose." I'm not referring to an awful piece of software by that name [1]. This post will look at a particular rose with k = 2/3.

My previous post looked at

r = cos(2/3)

and gave the plot below.

rose23.png

Unlike the case where k is an integer, the petals overlap.

In this post I'd like to look at two things:

  1. The curvature in the figure above, and
  2. Differences between polar plots in Python and Mathematica
Curvature

The graph above has radius 1 since cosine ranges from -1 to 1. The curve is made of arcs that are approximately circular, with the radius of these approximating circles being roughly 1/2, sometimes bigger and sometimes smaller. So we would expect the curvature to oscillate roughly around 2. (The curvature of a circle of radius r is 1/r.)

The curvature can be computed in Mathematica as follows.

 numerator = D[x[t], {t, 1}] D[y[t], {t, 2}] - D[x[t], {t, 2}] D[y[t], {t, 1}] denominator = (D[x[t], t]^2 + D[y[t], t]^2)^(3/2) Simplify[numerator / denominator]

This produces

rose23_curvature.svg

A plot shows that the curvature does indeed oscillate roughly around 2.

rose23_kappa.png

The minimum curvature is 13/9, which the curve takes on at polar coordinate (1, 0), as well as at other points. That means that the curve starts out like a circle of radius 9/13 0.7.

The maximum curvature is 3 and occurs at the origin. There the curve is approximately a circle of radius 1/3.

Matplotlib vs Mathematica

To make the plot we've been focusing on, I plotted

r = cos(2/3)

in Mathematica, but in matplotlib I had to plot

r = |cos(2/3)|.

In both cases, runs from 0 to 8. To highlight the differences in the way the two applications make polar plots, let's plot over 0 to 2 with both.

Mathematica produces what you might expect.

 PolarPlot[Cos[2 t/3], {t, 0, 2 Pi}]

polar_mmca.png

Matplotlib produces something very different. It handles negative r values by moving the point r = 0 to a circle in the middle of the plot. Notice the r-axis labels at about 22 running from -1 to 1.

 theta = linspace(0, 2*pi, 1000) plt.polar(theta, cos(2*theta/3))

polar_python.png

Note also that in Mathematica, the first argument to PolarPlot is r() and the second is the limits on . In matplotlib, the first argument is and the second argument is r().

Note that in this particular example, taking the absolute value of the function being plotted was enough to make matplotlib act like I expected. That's only happened true when plotted over the entire range 0 to 8. In general you have to do more work than this. If we insert absolute value in the plot above, still plotting from 0 to 2, we do not reproduce the Mathematca plot.

 plt.polar(theta, abs(cos(2*theta/3)))

polar_cusp.png

More polar coordinate posts

[1] Rational Rose was horribly buggy when I used it in the 1990s. Maybe it's not so buggy now. But I imagine I still wouldn't like the UML-laden style of software development it was built around.

The post Playing around with a rational rose first appeared on John D. Cook.

OzJ8rraNDEs
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments