A6 · Lesson 51 · Lab: curves in code
Lengths, areas and phases from parametric and polar curves
The perimeter of an ellipse has no formula in elementary functions, yet a few lines of Python give it to ten digits. A scope in XY mode draws an ellipse whose shape encodes the phase between two signals, and Python can read that phase back from the samples. In this lab you'll compute arc lengths and polar areas numerically, check them against exact answers where they exist, and measure a phase from a Lissajous figure's data.
- The curve is a Lissajous figure, , : what a scope shows in XY mode for two equal sines with a phase difference .
- At it's a line; at 90° a circle; in between, a tilted ellipse.
- The readout is the height where it crosses the axis, which is .
Predict
A scope's Lissajous ellipse crosses the axis at 0.5 (for a peak of 1). What is the phase difference?
30°, or 150°: where , , so the crossing height is . The tilt of the ellipse (rising or falling) tells which of the two it is. Reading the phase from samples does better than reading a crossing by eye, using every point instead of one.
Name it
Arc length of a parametric curve
. When the speed has no simple antiderivative, as for an ellipse, Simpson's rule on the speed converges fast. Ramanujan's approximation, , is a check good to a few parts per million for moderate eccentricity.
Area of a polar region
. A cardioid encloses .
Phase from samples
With and sampled evenly over one period,
by the orthogonality of sines and cosines. So = atan2(2*mean(y*cos t), 2*mean(y*sin t)), using all the samples.
Worked example
Find the perimeter of the ellipse with semi-axes 3 and 2.
Show the solution
- Set up the integral.
- Evaluate it numerically. Simpson's rule with 1000 slices gives 15.865 440.
- Compare with Ramanujan's formula. It gives 15.865 438: they agree to two parts in ten million.
- Compare with a circle. A circle of the same average radius, 2.5, has circumference 15.708: an ellipse is a little longer.
Answer the perimeter is 15.865 440.
Worked example
A cable with = 1000 m spans 200 m. Find its length numerically and exactly.
Show the solution
- Set up the integral.
- Evaluate it numerically. Simpson's rule gives 200.333 500 04 m.
- Find the exact value.
- Compare with the span. The cable is 33 cm longer than the span.
Answer the cable is 200.333 500 04 m long, 33 cm more than its span.
Check
What does Ramanujan's formula give for the perimeter of an ellipse with semi-axes 3 and 1?
Check
Two equal sines differ in phase by 60°. Where does their Lissajous ellipse cross the axis, for a peak of 1?
Check
Write arc_length(dx, dy, a, b, n=1000) returning by Simpson's rule, where dx and dy are the derivative functions. Set L to the perimeter of the ellipse with semi-axes 3 and 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write polar_area(r, a, b, n=1000) returning by Simpson's rule. Set A to the area inside the cardioid .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples and at 1000 points over one period, with an unknown . Set phi to the phase measured from all the samples, using the orthogonality sums in the reading.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A catenary with = 200 m spans 100 m. Use your arc_length idea with as the parameter to set L_num to its length by Simpson's rule, and L_exact to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The area under one arch of the cycloid , is . Set A to it by Simpson's rule (1000 slices) and exact to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does measuring phase from all the samples beat reading where the Lissajous figure crosses the axis?
Reading the crossing uses essentially one point of the curve, so any noise there, any offset in the signals or any error in judging exactly where the axis is crossed goes straight into the answer. The orthogonality sums use every sample: multiplying by and and averaging over a whole period picks out exactly the in-phase and quadrature parts of , and random noise in individual samples averages down as the square root of their number. A DC offset or a harmonic at another frequency averages to zero against the sine and cosine too. This is the same principle a lock-in amplifier or a network analyzer uses to measure phase precisely.
Practice
Keep practicing
6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.