Showing posts with label mathematics. Show all posts
Showing posts with label mathematics. Show all posts

Mar 1, 2014

The Butterfly Theorem

Fig. 1, C is the midpoint of a chord EF. PQ and UV are two chords passing through C. PV meets EF at X. UQ meets EF at Y. The butterfly theorem says, CX = CY.    
The Butterfly Theorem is a classical result in Euclidean geometry. It gives a beautiful shape of butterfly (Fig. 2) along with two equal length segments.

Fig. 2, the butterfly in the butterfly theorem
Fig. 3, proof of the theorem. O is the center of the circle. M, N are midpoint of the chord PV and UQ respectively. 

Poof:

Let M, N be the midpoint of chord PV and UQ respectively. O is the center of the circle.

Points P, V, Q, U are on the same circle. So $\angle VPQ = \angle VUQ$ and $\angle PVU = \angle PQU$. So  $\triangle CPV \simeq \triangle CUQ$. So $\frac{MV}{NQ} = \frac{PV/2}{UQ/2} = \frac{PV}{UQ} = \frac{VC}{QC}$.

$\frac{MV}{NQ} = \frac{VC}{QC}$ plus $\angle PVU  = \angle PQU$ implies $\triangle MVC \simeq \triangle CQN$. Thus $\angle VMC = \angle CNQ$.

OM is perpendicular to PV. ON is perpendicular to UQ. OC is perpendicular to EF (CX, CY). So O, M, X, C are on the same circle. O, C, Y, N are on the same circle. Thus, $\angle XOC = \angle XMC = \angle YNC = \angle YOC$. Note that OC is perpendicular to EF. Therefore, CX = CY.

The proof of the theorem gives us another butterfly (Fig. 4), which also consists of a pair of similar triangles.

Fig. 4. 


Dec 7, 2013

Frenet Tube


Given a 3D curve $\vec{r}(t) = (x(t), y(t), z(t)), t \in I=[0,1]$,  Tubify[ {x, y, z},  a] turns it into a tube around the curve. The Mathematica Tube[] has similar function (works on lines). The essential thing is to find the unit circle in the normal plane for each point (Shown in Fig. 1). The tangential vector is simply $\vec{\alpha} = \vec{r}'/|\vec{r}'|$, where $\vec{r}' = \mathrm{d} \vec{r}/\mathrm{d}t$. The normal vector is $\vec \beta = \vec{\alpha}' / |\vec{\alpha}'| = \frac{\vec{r}'' |\vec{r}'|^2 - \vec{r}' \vec{r}'\cdot\vec{r}''}{|\vec{r}'| \sqrt{|\vec{r}''|^2 |\vec{r}'|^2 - (\vec{r}'\cdot\vec{r}'')^2} }$. The binormal vector is $\vec{\gamma} = \vec{\alpha} \times \vec{\beta} =  \frac{\vec{r}' \times \vec{r}''  }{\sqrt{|\vec{r}''|^2 |\vec{r}'|^2 - (\vec{r}'\cdot\vec{r}'')^2} } $.

Fig. 1: black, $\vec{\alpha}$, green $\vec{\beta}$, blue $\vec{\gamma}$. 

Tubify[{x_, y_, z_}, r_] :=
 ({x[#1], y[#1], z[#1]}
    + (r[#1] Cos[#2])/
      Norm[(Norm[{x'[#1], y'[#1], z'[#1]}]^2 {x''[#1], y''[#1], 
           z''[#1]} - {x'[#1], y'[#1], z'[#1]}.{x''[#1], y''[#1], 
            z''[#1]} {x'[#1], y'[#1], z'[#1]})] (Norm[{x'[#1], y'[#1],
            z'[#1]}]^2 {x''[#1], y''[#1], 
         z''[#1]} - {x'[#1], y'[#1], z'[#1]}.{x''[#1], y''[#1], 
          z''[#1]} {x'[#1], y'[#1], z'[#1]})
    + (r [#1] Sin[#2] )/
      Norm[{-z'[#1]*y''[#1] + z''[#1]*y'[#1], 
        z'[#1]*x''[#1] - z''[#1]*x'[#1], -y'[#1]*x''[#1] + 
         x'[#1]*y''[#1]}] {-z'[#1]*y''[#1] + z''[#1]*y'[#1], 
      z'[#1]*x''[#1] - z''[#1]*x'[#1], -y'[#1]*x''[#1] + 
       x'[#1]*y''[#1]}) &

All the arguments are functions.

Example 1:
Show[ParametricPlot3D[
  Tubify[{(2 + Cos[3 #]) Cos[ #] &, (2 + Cos[3 #]) Sin[#] &, 
     Sin[3 #] &}, 0.25 &][u, v],
  {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Opacity[0.2],
  Mesh -> None, Boxed -> True, Axes -> False, BoxRatios -> Automatic, 
  PerformanceGoal -> "Quality", PlotPoints -> 80, MaxRecursion -> 0, 
  PlotLabel -> 
   Style[TraditionalForm /@ {(2 + Cos[3 t]) Cos[ 
        t], (2 + Cos[3 t]) Sin[t], Sin[3 t]}, 20]
  ],
 ParametricPlot3D[{(2 + Cos[3 u]) Cos[ u], (2 + Cos[3 u]) Sin[u], 
   Sin[3 u]}, {u, 0, 2 Pi}, 
  PlotStyle -> Directive[{Red, Opacity[1], Thick}]], ImageSize -> 600
 ]

A similar code using Tube[]:

ParametricPlot3D[
  {(2 + Cos[3 u]) Cos[ u], (2 + Cos[3 u]) Sin[u], 
   Sin[3 u]}, {u, 0, 2 Pi}, PlotStyle -> Opacity[0.2],
  Mesh -> None, Boxed -> True, Axes -> False, BoxRatios -> Automatic, 
  PerformanceGoal -> "Quality", PlotPoints -> 80, MaxRecursion -> 0, 
  PlotLabel -> 
   Style[TraditionalForm /@ {(2 + Cos[3 t]) Cos[ 
        t], (2 + Cos[3 t]) Sin[t], Sin[3 t]}, 20]
  ]/.Line[pts_, rest___] :> Tube[pts, 0.1, rest]

Fig. 2

Example 2, trefoil knot:


Show[ParametricPlot3D[
  Tubify[{Sin[#] + 2 Sin[2 #] &, Cos[#] - 2 Cos[2 #] &, -Sin[3 #] &}, 
    0.25 &][u, v],
  {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Opacity[0.3],
  Mesh -> None, Boxed -> True, Axes -> False, BoxRatios -> Automatic, 
  PerformanceGoal -> "Quality", PlotPoints -> 100, MaxRecursion -> 0, 
  PlotLabel -> Style[TraditionalForm /@ trefoil[t], 20]
  ], ImageSize -> 600
 ]

Fig. 3 Trefoil Knot

Similarly, we can also define the Frenet's Ribbon:
Ribbonize[{x_, y_, z_}, r_] :=
 ({x[#1], y[#1], z[#1]}
    + r [#1] #2 /
      Norm[{-z'[#1]*y''[#1] + z''[#1]*y'[#1], 
        z'[#1]*x''[#1] - z''[#1]*x'[#1], -y'[#1]*x''[#1] + 
         x'[#1]*y''[#1]}] {-z'[#1]*y''[#1] + z''[#1]*y'[#1], 
      z'[#1]*x''[#1] - z''[#1]*x'[#1], -y'[#1]*x''[#1] + 
       x'[#1]*y''[#1]}) &

Fig. 4, Trefoil Ribbon


Fig. 5, Helix Ribbon

more examples:

Fig. 6, A Seashell Surface
Fig. 7, Double Helix (cf. DNA)
Fig. 8, A Figure-eight Knot

ParametricPlot3D[
 Tubify[{#/Pi Cos[#] &, #/Pi Sin[#] &, #/Pi &}, Sin[#/4] &][u, u*80],
 {u, 0, 4 Pi}, PlotStyle -> Directive[{Red, Thick, Opacity[0.8]}],
 Mesh -> None, Boxed -> True, Axes -> False, BoxRatios -> Automatic,
 PlotRange -> All, PerformanceGoal -> "Quality", MaxRecursion -> 0, 
 PlotPoints -> 2560, PlotLabel -> Style["", 20], 
 ImageSize -> 500
 ]
Fig. 9, a coilfied 3D curve

Oct 16, 2013

Zeros of the Legendre Polynomials


Legendre functions (Legendre polynomials) are the solutions of the following linear Ordinary Differential Equation (ODE), \[
\frac{\mathrm{d}}{d x}\left[ (1-x^2) \frac{\mathrm{d}}{\mathrm{d}x} P_n(x) \right] + n(n+1)P_n(x) = 0
\]

The Legendre function $P_n(x)$ is a degree $n$ polynomial. It has $n$ distinct roots within (-1,1), $x_{n,k}, k=1,2,\cdots n$, $x_{n,1} < x_{n,2} < \cdots < x_{n,n}$. There is no analytical solution for high order Legendre polynomials. It is useful to know the analytical bounds of the roots.

According to Bruns, Markoff, Stieltjes and Szego [1], the roots satisfy the following inequality, \[
\cos\frac{(n-k+1)\pi}{n+1} < x_{n,k} < \cos\frac{(n-k+\frac{3}{4})\pi}{n+\frac{1}{2}}
 \] for $k = 1, \cdots \left[\frac{n}{2}\right]$. For the other half, recall $x_{n,n-k+1} = -x_{n,k}$.

It may also be useful to give a pair of global bounds, \[
\cos\frac{(n-k+\frac{1}{2})\pi}{n+\frac{1}{2}} < x_{n,k} < \cos\frac{(n-k+1)\pi}{n+\frac{1}{2}}
\] for $k=1,2,\cdots n$, although this is a coarse one.

The roots of the Legendre polynomials also admit asymptotic expansion due to Francesco Tricomi [2]. Let $\theta_{n,k} = \frac{n-k+3/4}{n+1/2}\pi$. Then the $k$-th root (in ascent order) is \[
x_{n,k} = \left\{1 - \frac{1}{8n^2} + \frac{1}{8n^3} - \frac{1}{384n^4}\left( 39 - \frac{28}{\sin^2\theta_{n,k}} \right) + \mathcal{O}(n^{-5})\right\} \cos\theta_{n,k}, \] which can be improve by Newton's algorithm $x_{\nu+1} = x_{\nu} - \frac{1-x_\nu^2}{n} \frac{P_n(x_\nu)}{P_{n-1}(x_\nu) -x_\nu P_n(x_\nu)}$.

Another approximation due to Gatteschi and Pittaluga [3] is \[
x_{n,k} = \cos\left\{ \theta_{n,k} + \frac{1}{16(n+1/2)^2}(\cot\frac{1}{2}\theta_{n,k} - \tan\frac{1}{2}\theta_{n,k}) \right\} + \mathcal{O}(n^{-4}).
\]

Let $x_{n,k}$ be the $k$-th root of $P_n(x)$, $\xi_{n,k}$ be its approximations.

The $x_{n,k} \simeq \cos\theta_{n,k}$ is a pretty good estimator of the location $k$ of Gaussian nodes from $x_{n,k}$.


Last but not least, the zeros are the nodes of the Gaussian quadrature. \[
 \int_{-1}^{+1} \mathrm{d}x f(x) \simeq \sum_{k=1}^n w_{n,k} f(x_{n,k})
\] where $w_{n,k} = \frac{2}{(1-x_{n,k}^2) \left[ P'_n(x_{n,k}) \right]^2}$ are called the Gaussian weights. Gaussian quadrature can be illustrated by the bellow figure ($n = 16$).

References:

[1] Gabriel Szego, Inequalities for the Zeros of Legendre Polynomials and Related Functions, Transactions of the American Mathematical Society, Vol. 39, No. 1 (1936)

[2] F. G. Tricomi, Sugli zeri dei polinomi sferici ed ultrasferici, Ann. Mat. Pura Appl., 31 (1950), pp. 93–97; F.G. Lether and P.R. Wenston, Minimax approximations to the zeros of $P_n(x)$ and Gauss-Legendre quadrature, Journal of Computational and Applied Mathematics Volume 59, Issue 2, 19 May 1995, Pages 245–252

[3] L. Gatteschi and G. Pittaluga, An asymptotic expansion for the zeros of Jacobi polynomials, in Mathematical Analysis. Teubner-Texte Math., 79 (1985), pp. 70–86

Source codes:

John Burkardt (GNU LGPL): http://people.sc.fsu.edu/~jburkardt/cpp_src/quadrule/quadrule.html

pomax.github.io: http://pomax.github.io/bezierinfo/legendre-gauss.html

rosettacode: http://rosettacode.org/wiki/Numerical_integration/Gauss-Legendre_Quadrature

Mathematica:
Needs["NumericalDifferentialEquationAnalysis`"]

GaussianQuadratureWeights[n, a, b, prec]

Oct 9, 2013

Smoothing a polygon


Ref. [1] has an interesting observation. For any closed polygon, if one takes the midpoint repeatedly, the polygon will be eventually smoothed out. The authors observed that the curves will become an elliptic.

The mapping is in fact independent in x and y directions. Therefore, after large enough iteration, the x and y coordinate will be "in phase", i.e. belong to the same eigensubspace.









randline[n_Integer, a_: - 1, b_: 1] := RandomReal[{a, b}, {n, 2}]

mpt[pts_, n_: 3] := 
 Table[Sum[pts[[Mod[i + j - 1, Length@pts, 1]]], {j, 1, n}]/n, {i, 1, 
   Length[pts]}]

nl[npts_, nitr_, n_: 2, a_: - 1, b_: 1] := 
  NestList[mpt[#, n] &, randline[npts, a, b], nitr];

randplot[npt_, nit_, nst_: 10, na_: 2, pt_: False, init_: False, a_: - 1,
   b_: 1] :=
 Module[{n, i0 = Min[Max[1, nst], nit + 1]},
  n = nl[npt, nit, na, a, b];
  Show[
   If[pt, 
    Graphics[
     Flatten[Table[{Hue[(i - i0)/(nit + 1 - i0)], 
        Line[closeline[n[[i]]]], PointSize[Medium], 
        Point[n[[i]]]}, {i, nst, nit + 1}], 1]],
    Graphics[
     Flatten[Table[{Hue[(i - nst)/(nit + 1 - i0)], 
        Line[closeline[n[[i]]]]}, {i, nst, nit + 1}], 1]]
    ], If[init,
    Graphics[{Opacity[0.6], Line[closeline[n[[1]]]]}],
    Graphics[]
    ]
   ]
  ]

I here also present the spectrum


reference:
[1]:http://www.cs.cornell.edu/cv/ResearchPDF/PolygonSmoothingPaper.pdf

Oct 6, 2013

The Pythagorean theorem in "Zhou Bi Suan Jing" (周髀算经)


The celebrated Phythagorean theorem gives the relation between the sides of a right triangle: \[
a^2 + b^2 = c^2
\] where $a,b,c$ are the lengths of the sides with $c$ the one opposite to the right angle.

In China, the theorem is known as "Gou Gu Theorem" (勾股定理) or "Gou Gu Xian Theorem" (勾股弦定理). It first appears in the oldest Chinese mathematical book that survives today, the "Zhou Bi Suan Jing" (周髀算经). "Zhou" refers to the ancient dynasty Zhou (周); "Bi" means arm and according to the book, it refers to the gnomon of the sundial. The book is dedicated to astronomical observation and calculation. "Suan Jing" or "classic of arithmetic" were appended in later time to honor the achievement of the book in mathematics.

In Chapter I.1, In a dialog between "the Duke of Zhou" (周公) and "Gao of Shang" (商高), Gao said,
"故折矩, 以為句廣三, 股修四,徑隅五."
"So for the half of the rectangle,  if Gou is three, Gu is four, then Xian is Five."

Gou (勾/句) , Gu (股), Xian (弦) are the Chinese names of the three sides of a triangle. These texts essentially give a Pythagorean triplet (3, 4, 5), a triple of numbers that satisfies the Pythagorean equation $a^2 + b^2 = c^2$. Further explanation appears in Chaper I.2 in a dialog between "Rong Fang" (荣方) and "Chen Zi"  (陈子). Chen Zi in explaining a problem concerning of the measurement of the position of the sun, said,
"若求邪至日者, 以日下為句, 日高為股, 句股各自乘, 并而開方除之, 得邪至日."
"Suppose the distance to the sun is wanted. Let the distance to the projection of the sun on the ground be Gou, the distance of the sun to the ground be Gu. Square them respectively, add together and take the square root. Then the distance to the sun is obtained." 

Now the Pythagorean theorem is given.

The author of Zhou Bi is unknown, nor the year was it written. But according to the texts, it is a collection of the astronomical and mathematical methods of the Shang and Zhou dynasty ( 1100 - 1000 BC). The Duke of Zhou is the brother of the creator of Zhou dynasty, which had been a state in the Shang dynasty. Gao of Shang was apparently a figure in the Shang dynasty, as suggested by his name. If this is true, the Pythagorean theorem was proposed as early as 1000BC, contrast of Pythagoras who lived between 570 BC - 495 BC. Other people argue that Zhou Bi was compiled by more than one author and settled around 200 BC.

references:

http://www-groups.dcs.st-and.ac.uk/history/HistTopics/Chinese_overview.html





.

Sep 12, 2013

Quiz: area of the shaded part

Inside the above rectangle, the area of the light-blue triangle is 2 and the area of the light-yellow triangle is 3. Question: what is the area of the gray polyon?


Mar 15, 2013

On the day of Pi - in honor of Zu Chong Zhi (祖沖之)


Yesterday, the 14th day of March, is known as the day of Pi because of its numerical similarity with Pi, the ratio of circle circumference and its diameter:
\[ \pi = 3.14159265758979... ... \]

The Book of Sui (history record of Sui dynasty) records Zu Chong Zhi's (祖沖之) estimate of Pi, called Yuan Zhou Lü (圆周率) in Chinese [2]:

And I translate it here:
Among the prominent ancient problems, the circumference is three if the circle diameter is one. This value is not accurate. From Liu Xin (劉歆), Zhang Heng (張衡), Liu Hui (劉徽), Wang Fan (王蕃), Pi Yan Zong (皮延宗) etc., new results have been reported. The value has been updated from time to time. Late in Song (劉宋) Dynasty, south Xu state (南徐州) [4] governor Zu Chong Zhi (祖沖之), further initiated the so-called fine approximation.

Assuming the circle diameter is one zhang(丈), its circumference is less than three zhang(丈) one chi(尺) four cun(寸) one fen(分) five li(厘) nine hao(豪) two miao(秒) seven hu(忽) and greater than three zhang(丈) one chi(尺) four cun(寸) one fen(分) five li(厘) nine hao(豪) two miao(秒) six hu(忽) [1]. The true value lies between these two numbers. As an approximation, the fine approximate (密律) is that for a circle with diameter one hundred thirteen its circumference is three hundred fifty five. The rought approximate (約律) is that for a circle with diameter seven, its circumference is twenty two. Zu also provided square root and square arithmetics, together with positive and negative numbers. His method is very precise, best in arithmetic. Zu wrote a monograph called Zhui Shu (綴術) [3], is so deep that not well understood among scholars. 
These texts clearly state Zu Chong Zhi's work on Pi, as early as the 5th century. This is a great achievement in mankind history of mathematics.


[1]: 丈尺寸分厘毫秒忽 are all decimalized length units, widely used in Greater China region (CJKV).
[2]: The reader need CJK fonts to display Chinese characters properly. Literally, 圆=circle, 周=circumference, 率=ratio. It's understood that the ratio is taken with respect to the diameter or 径.
[3]: Zhui Shu can be roughly translated as numerical methods. Zhui Shu had been chosen into a collection of mathematical textbooks since Tang Dynasty (唐). It was lost after Song Dynasty (宋) (A different Song Dynasty from Zu Chong Zhi's time).
[4]: In present day Zhejiang Province, China