A651 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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, x=sin⁡t, y=sin⁡(t+φ): what a scope shows in XY mode for two equal sines with a phase difference φ.
  • At φ=0 it's a line; at 90° a circle; in between, a tilted ellipse.
  • The readout is the height where it crosses the y axis, which is sin⁡φ.

Predict

A scope's Lissajous ellipse crosses the y axis at 0.5 (for a peak of 1). What is the phase difference?

Name it

Arc length of a parametric curve

L=∫abx˙2+y˙2dt. When the speed has no simple antiderivative, as for an ellipse, Simpson's rule on the speed converges fast. Ramanujan's approximation, π[3(a+b)−(3a+b)(a+3b)], is a check good to a few parts per million for moderate eccentricity.

Area of a polar region

A=12∫αβr(θ)2dθ. A cardioid r=1+cos⁡θ encloses 3π2.

Phase from samples

With x=sin⁡t and y=sin⁡(t+φ) sampled evenly over one period,

2ysin⁡t¯=cos⁡φ,2ycos⁡t¯=sin⁡φ

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
  1. Set up the integral. L=∫02π9sin2⁡t+4cos2⁡tdt
  2. Evaluate it numerically. Simpson's rule with 1000 slices gives 15.865 440.
  3. Compare with Ramanujan's formula. It gives 15.865 438: they agree to two parts in ten million.
  4. 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 a = 1000 m spans 200 m. Find its length numerically and exactly.

Show the solution
  1. Set up the integral. L=∫−100100cosh⁡(x/1000)dx
  2. Evaluate it numerically. Simpson's rule gives 200.333 500 04 m.
  3. Find the exact value. 2000sinh⁡(0.1)=200.33350004m
  4. 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 y axis, for a peak of 1?

Check

Write arc_length(dx, dy, a, b, n=1000) returning ∫abx˙2+y˙2dt 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 12∫abr(θ)2dθ by Simpson's rule. Set A to the area inside the cardioid r=1+cos⁡θ.

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 x=sin⁡t and y=sin⁡(t+φ) 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 y=acosh⁡(x/a) with a = 200 m spans 100 m. Use your arc_length idea with x as the parameter to set L_num to its length by Simpson's rule, and L_exact to 2asinh⁡S2a.

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 x=t−sin⁡t, y=1−cos⁡t is ∫ydx=∫02π(1−cos⁡t)2dt. Set A to it by Simpson's rule (1000 slices) and exact to 3π.

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?

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.