The following code is a bit clumsy, but it constructs a variable number (n) of epicycles using the values from the radii and angularVel tables that follows the path of a parametric given as a sum of sinusoids. This code builds the epicycles which trace the parametric $\gamma(t)=e^{it}+\frac{1}{2}e^{7it}+\frac{i}{3}e^{-17it}$. So, given any function written as the sum of circles:
$z(t)=\sum_{i=1}^{n}R_1e^{ik_nt}$, where $R_n$ and $k_n$ are the radius and angular velocity of each circle respectively, my code will trace its path.
Now, as you can imagine, my goal is to visualize the Fourier Series as the sum of circles (=epicycles), however, for functions of real coefficients the Fourier Series is just the linear combination of sines and cosines alone, which in complex form are expressed like different variations of this: ${e^{ix}-e^{-ix}}$, and in that form I do not know how to feed it to my program.
QUESTION: How would you create a list of radii and angular velocities to create epicycles for something like this $f(x)=x^2$, whose 2nd order fourier series is $-2e^{-ix}-2e^{ix}+\frac{1}{2}e^{-2ix}+\frac{1}{2}e^{2ix}+\frac{\pi^2}{3}$?
This may not exactly be a programming question, I will also try the math forum but seeing the code is important for anyone to help me.
All help is appreciated.
Clear["Global`*"]
n = 3;
radii = {I/3, 1/2, 1, 15, 18};
angularVel = {-17, 7, 1, -1, -6};
circles = Table[radii[[i]]*E^((angularVel[[i]])*I*t), {i, 1, n}];
circleCoords =
Table[{N[Re[circles[[i]]]], N[Im[circles[[i]]]]}, {i, 1, n}];
harmonicCircles =
Table[Sum[circleCoords[[j]], {j, i + 1, n}], {i, 1, n - 1}];
AppendTo[harmonicCircles, {5, 2}];
pt = Sum[circleCoords[[i]], {i, 1, n}];
(*--------------------------------------*)
circlesForGraphic =
Table[Circle[harmonicCircles[[i]], Abs[radii[[i]]]], {i, 1, n - 1}];
PrependTo[circlesForGraphic, Circle[{0, 0}, radii[[n]]]];
ordering =
Table[Text[i, harmonicCircles[[i]], Offset[{3, 3}]], {i, 1, n}];
PrependTo[ordering, Text[n, {0, 0}, Offset[{3, 3}]]];
epicyclesGraphic =
Graphics[{PointSize[0.025], Purple, Thick, Point[{0, 0}], Point[pt],
ordering, circlesForGraphic}, PlotRange -> Automatic];
var = 400;
data = {};
For[t = 1, t <= var, t = t + 0.1,
AppendTo[data, pt];
]
ListPlot[data]
shape = ListCurvePathPlot[data, PlotTheme -> "Detailed"];
Dynamic[Show[epicyclesGraphic, shape]]
{Slider[Dynamic[t], {0, 10}], Dynamic[t]}
Dynamic[circleCoords]
Dynamic[epicyclesGraphic];
{-2, -2, 1/2, 1/2, Pi^2/3}
and{-1, 1, -2, 2, 0}
respectively. $\endgroup$ – user484 Nov 26 '15 at 9:53