Menggambar hati di Python

Gambar hati (heart) sering digunakan orang sebagai simbol untuk mengekspresikan perasaan cinta. Betulkah demikian? Anggap saja betul. Entah itu anak-anak, remaja, atau orang dewasa pasti tau gambar hati. Para remaja yang sedang jatuh cinta sama lawan jenisnya sering saya jumpai senang menggambar hati (heart). Entah apa hubungan antara gambar hati dengan cinta. Love, begitulah kata para remaja sekarang, masa indah bagi mereka.

Nah, mau tau cara menggambar hati dengan persamaan matematika? Berikut ini beberapa gambar hati yang saya buat dengan menggunakan bahasa pemrograman Python. Untuk membuat plot terhadap persamaan matematika digunakan matplotlib, yaitu sebuah library khusus python untuk membuat plot 2D dari suatu array data. Adapun untuk pengolahan dan komputasi array data atau objek Python mempunyai library khusus, yaitu NumPy. Jadi kedua library tersebut harus sudah terintegrasi dengan editor python yang anda gunakan.

import matplotlib.pylab as plt
import numpy as np
x = np.linspace(-np.pi, np.pi)
plt.polar(x, 1+np.sin(x), linewidth=3.0)
plt.axis([0, 2, 0, 2])
plt.text(1.0,-1.0, r'$r=1+\sin \theta$', fontsize=20)
plt.show()

Atau :


import matplotlib.pylab as plt
import numpy as np
x = np.linspace(-np.pi, np.pi)
plt.polar(x, 1-np.sin(x), linewidth=3.0)
plt.axis([0, 2, 0, 2])
plt.text(2.0,1.0, r'$r=1-\sin\theta$', fontsize=20)
plt.show()

Dan inilah gambar yang ketiga,

import matplotlib.pylab as plt
import numpy as np
x = np.linspace(-2,2,1000)
y1 = np.sqrt(1-(abs(x)-1)**2)
y2 = -3*np.sqrt(1-(abs(x)/2)**0.5)
plt.fill_between(x, y1, color='pink')
plt.fill_between(x, y2, color='pink')
plt.xlim([-2.5, 2.5])
plt.ylim([-3.5, 1.5])
plt.text(0, -0.4, 'Heart For You', fontsize=20, fontweight='bold',
           color='blue', horizontalalignment='center')
plt.text(0, -1.0, r'$y_1=\sqrt{1-(|x|-1)^2}$', fontsize=16,
           horizontalalignment='center')
plt.text(0, -1.5, r'$y_2=-3\sqrt{1-\left(\frac{|x|}{2}\right)^{\frac{1}
           {2}}}$', fontsize=16, horizontalalignment='center')
plt.show()

Persamaan-persamaan matematika untuk gambar hati diantaranya saya temukan di halaman ini.

Selamat bersenang-senang! 🙂

Boy’s Surfaces

Boy’s surface is a nonorientable surface found by Werner Boy in 1901. Boy’s surface is an immersion of the real projective plane in 3-dimensional without infinities and singularities, but it meets itself in a triple point (self-intersect). The images below are generated using 3D-XplorMath, and with the “optimal” Bryant-Kusner parametrization when a= 0.5, -1.45 < u < 0, and 0 < v < 2\pi :

Boy's Surface (Bryant-Kusner)

Other viewpoints :

Boy's Surface (Bryant-Kusner) other viewpoints

Projective Plane

There are many ways to make a model of the Boy’s surface using the projective plane, one of them is to take a disc, and join together opposite points on the edge with self intersection (note : In fact, this can not be done in three dimensions without self intersections); so the disc must pass through itself somewhere. The Boy’s surface can be obtained by sewing a corresponding band (Möbius band) round the edge of a disc.

The \mathbb{R}^{3} Parametrization of Boy’s surface

Rob Kusner and Robert Bryant discovered the beautiful parametrization of the Boy’s surface on a given complex number z, where \left | z \right |\leq 1, so that giving the Cartesian coordinates \left ( X,Y,Z \right ) of a point on the surface.

In 1986 ApĂ©ry gave  the analytic equations for the general method of nonorientable surfaces. Following this standard form, \mathbb{R}^{3} parametrization of the Boy’s surface can also be written as a smooth deformation given by the equations :

x\left ( u,v \right )= \frac {\sqrt{2}\cos\left ( 2u \right ) \cos^{2}\left ( v \right )+\cos \left ( u \right )\sin\left ( 2v \right ) }{D},

y\left ( u,v \right )= \frac {\sqrt{2}\sin\left ( 2u \right ) \cos^{2}\left ( v \right )-\sin \left ( u \right )\sin\left ( 2v \right ) }{D},

z\left ( u,v \right )= \frac {3 \cos^{2}\left ( v \right )}{D}.

where

D= 2-a\sqrt{2}\sin\left ( 3u \right )\sin\left ( 2v \right ),

a varies from 0 to 1.

Here are some links related to Boy’s surface :

Ekspresi Rekursif Algoritma BPNN

Di top pencarian saya temukan kata kunci tentang ekspresi rekursif yang secara eksplisit dinyatakan oleh persamaan (10) pada posting saya sebelumnya tentang algoritma BPNN (backpropagation neural networks). Algoritama tersebut, seperti yang telah saya tulis, menggunakan metode gradient descent, namun untuk penurunan rumusnya dalam konteks struktur algoritma pembelajaran jaringan backpropagation, perlu pemahaman sedikit lebih dalam tentang persamaan diferensial parsial (PDE) termasuk pula aturan rantai (chain rule) di dalamnya. Metode ini bertujuan untuk meminimalkan error jaringan dengan cara memperbarui bobot w di setiap langkah iterasi. Untuk itu diperlukan suatu ekspresi atau persamaan yang mengaitkan perubahan error E di setiap layer, dimana nantinya didapat E_{n+1}<E_{n}, seperti tampak pada gambar berikut :

Maka diperlukan rumus untuk ekspresi rekursif antara \partial E/\partial x_{k}^{n}, bobot w, fungsi transfer non-linier dari jumlah input di setiap layer (s), dan \partial E/\partial x_{k}^{n+1}, dimana simbol k di sini menandai neuron pada layer ke-n atau ke-(n+1). Untuk mencari hubungan rekursif tersebut digunakan aturan rantai (chain rule) yang langkah-langkahnya adalah sebagai berikut.

Pertama, kita gali turunan parsial error yang mengacu kepada output neuron pada persamaan (9) di posting sebelumnya, yang dapat ditulis menjadi,

\frac{\partial E}{\partial x_{m}^{n}}= \sum_{j=1}^{L}\frac{\partial E}{\partial s_{j}^{n+1}}\frac{\partial s_{j}^{n+1}}{\partial x_{m}^{n}}, …. (1)

dan karena

s_{j}^{n+1}= \sum_{i=1}^{N} w_{ij}^{n+1}x_{i}^{n} ….(2)

maka diperoleh

\frac{\partial s_{j}^{n+1}}{\partial x_{m}^{n}}= w_{mj}^{n+1}. ….(3)

Dengan mensubstitusikan persamaan (3) ke persamaan (1) diperoleh :

\frac{\partial E}{\partial x_{m}^{n}}= \sum_{j=1}^{L}\frac{\partial E}{\partial s_{j}^{n+1}}w_{mj}^{n+1} ….(4)

Karena x_{j}^{n+1}=f\left ( s_{j}^{n+1} \right ), maka

\frac{\partial E}{\partial s_{j}^{n+1}}= f'\left ( s_{j}^{n+1} \right ) \frac{\partial E}{\partial x_{j}^{n+1}}….(5)

Dan akhirnya, dengan mensubstitusikan persamaan (5) ke dalam persamaan (4) diperoleh hubungan rekursif tersebut, yaitu :

\frac{\partial E}{\partial x_{m}^{n}}= \sum_{j} w_{mj}^{n+1} f'\left ( s_{j}^{n+1} \right ) \frac{\partial E}{\partial x_{j}^{n+1}}….(6)

Persamaan (6) ini menunjukan apa yang sedang kita bicarakan ini, yaitu bahwa \partial E / \partial x_{m}^{n} bisa dinyatakan secara rekursif dengan melibatkan derivatif error terhadap output neuron pada layer berikutnya.

Deep Questions of Life

Often we have question about something (question) where the answer is already contained in it. It may be called analytic questions, that is the relation between them is the relation of identity. The question is just like the answer that is already contained in it. Or it’s like an ordered pair, the first member of the pair is the best possible question we could ask, and the second member of the pair is the answer to that question. But the intelligent robots in the following video have the wisdom and consideration about the type of question.

These intelligent robots ponder deep philosophical questions of life : “What is the best possible question, and what’s the best answer to it?” By Teja Krasek and Cliff Pickover, at Youtube.

It is not (only) numbers

Pythagoras declared that ‘all is number’, and everything could be understood in terms of numbers. It is not always easy to fully grasp the underlying philosophy of Pythagoras’s insights. We can, however, explore one of his most famous theorems which still bears his name today, concerning the triangle and its many ramifications.

Vesica PiscisVesica Piscis, which literally means “the bladder of a fish” in Latin, becames the core of all solids. Image from Wikipedia.

According to Plato, the circle and the interaction of two circles, where the center of each circle lies on the circumference of the other (the so-called Vesica Piscis), became the core of all solids. Following this train of thought, geometry becomes music, and music becomes cosmic harmony and the music of the spheres.

Vesica PiscisVesica Piscis with figures within. Image from dcsymbols.com.

It has been seen, however, that Pythagoras’s view, “all is numbers,” did not fully complying with the numbers which have been found at the time. Pythagoras himself only aware about rational numbers. So in Pythagoras time, numbers meant rational numbers. When Pythagoras and his students claimed that all things are numbers, they meant to imply that everything could be understood in terms of rational numbers. But, unfortunately, they soon discovered the irrational numbers which is, roughly speaking, inspired from by the phenomenon of  the diagonal of a unit square. Pythagoreans discovered that the diagonal of a unit square, \sqrt{2}, is not commensurable with its side. And this has given the area to be solved in other fashion, such as arithmetic or algebraic fashion. So that mathematics, particularly number theory, has been growing and developing with fascinating discoveries as we have seen today.

On the sipirit of ‘sacred teaching’ of Pythagoras, whatever numbers we actually do or attempt to discover, or just seek another method of its approximation and representation, let’s see and do not bother with this funny comic. This maybe make us smile for today :

Number LineComic : Number line by Jeff at xkcd.com

Humanities

When we talk about humanities, I have a different opinion. I go for the opposite direction : what does it mean for everything? In fact, we can not mean or measure something unless it accounts any fraction of mathematics, and thus with numbers. But is there some other areas that can not be understood in term of numbers?

How about humanities? There is sensitive area when we talk about humanities or judge on the human values. The values ​​of human beings are not only numbers, there are cultural minds that would be differs, such as theoritic values, economic values, solidarity values, politic values​​, religious values ​​and artistic values. The values are there in all people, differ from one person to another, between one society to another and between cultures with each other, not in quantity, but on the configuration of these values​​.

So, when we talk about humanities and the human values, it is not appropriate to measure these values with only positivist method of calculating or measuring with the set of numbers. Because humans have soul arrangements which is called cultural mind, which created the culture and living in a culture. Maybe, for this kind of values, we have to use another method, such as understanding method (Verstehen) instead of using positivist method of calculating and measuring.

Note : I just wrote this post in a few minutes, and attached the comic for fun without any tendency. I hope you enjoy as well as I enjoy the humor in my life. 🙂

Parametric Breather Pseudospherical Surface

Parametric breather surfaces are known in one-to-one correspondence with the solutions of a certain non-linear wave-equation, i.e., the so-called Sine-Gordon Equation. It turns out, solutions to this equation correspond to unique pseudospherical surfaces, namely soliton. Breather surface corresponds to a time-periodic 2-soliton solution.

Parametric breather surface has the following parametric equations :

x = -u+\frac{2\left(1-a^2\right)\cosh(au)\sinh(au)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)}

y = \frac{2\sqrt{1-a^2}\cosh(au)\left(-\sqrt{1-a^2}\cos(v)\cos\left(\sqrt{1-a^2}v\right)-\sin(v)\sin\left(\sqrt{1-a^2}v\right)\right)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)}

z = \frac{2\sqrt{1-a^2}\cosh(au)\left(-\sqrt{1-a^2}\sin(v)\cos\left(\sqrt{1-a^2}v\right)+\cos(v)\sin\left(\sqrt{1-a^2}v\right)\right)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)}

Where 0<a<1, u controls how far the tip goes, and v controls the girth.

When a=0.4, -13<u<13, and -38<v<38 :

With orthographic projection :

About Pseudospherical Surfaces :

Surface in \mathbb{R}^{3} having constant Gaussian curvature K= -1 are usually called pseudospherical surfaces.

If X : M \subset \mathbb{R}^{3} is a surface with Gaussian curvature K= -1 then it is known that there exists a local asymptotic coordinate system (x,t) on M such that the first and second fundamental forms are:

dx^{2}+dt^{2}+2 \cos{q}~dx~dt, and 2 \sin{q}~dx~dt,

where q is the angle between asymptotic lines (the x-curves and t-curves). The Gauss-Codazzi equations forM in these coordinates become a single equation, the sine-Gordon equation (SGE) :

q_{xt}= \sin{q}

The SGE is one of the model soliton equations.

References and Readings :

  • Chuu-Lian Terng. 2004. Lecture notes on curves and surfaces in \mathbb{R}^{3}, available here.
  • Chuu-Lian Terng. 1990s. About Pseudospherical Surfaces, available here.
  • Richard S Palais. 2003. A Modern Course on Curves and Surfaces, available here.

About 3D-XplorMath :

3D-XplorMath is a Mathematical Visualization program. The older original version, written in Pascal, runs only on Macintosh computers, but there is also a newer cross-platform Java version, called 3D-XplorMath-J which is written in the Java programming language; to use it, you must have Java 5.0 or higher installed on your computer.

Complex Continued Fractions and The Gaussian Integers

Continued fractions off er a useful method and representation of expressing numbers and functions. One of interesting ideas of this method is that any number can be represented by a point on the real line and that falls between two integers.

Several attempts have been made during the last 100 years to develop continued fraction algorithm for complex numbers[1]; such algorithm having properties that are known to possess on the regular continued fraction algorithm in the real numbers case.

In the real case, for example, let s be any real number, and if t is an integer, then

t\leq s<t+1.

There is one and only one such integer t for any given real s. The integer t is sometimes called the floor of s,

t= \left [ s \right ]

For example : 3= \left [ \pi \right ], -2= \left [-1.5 \right ].

For any real s with t= \left [ s \right ], there is a unique decomposition s= t+u where t is an integer and u is in the unit interval. So, u = 0 if and only if s is an integer.

The process of finding the continued fraction expansion of a real number is a recursive process that procedes one step at a time. Given any real number s, after k steps, the process goes like this one :

s= t_1+\frac{1}{t_2+\frac{1}{t_3+\frac{1}{...+\frac{1}{t_k+u_k}}}}

Which has integers t_{1}, t_{2}, . . . , t_{k} and real numbers u_{1}, u_{2}, ..., u_{k} that are members of the unit interval I with u_{1}, u_{2}, ..., u_{k-1} all positive.  We can write another representation :

s= \left [t_1,t_2,t_3,...,t_k+u_k \right].

If u_{k}=0, the process ends after k steps. Otherwise, the process continues at least one more step with

\frac{1}{u_k}= t_{k+1}+u_{k+1}.

In this way one associates with any real number s a sequence, which could be either finite or infinite, t_{1}, t_{2}, . . . of integers. This sequence is called the continued fraction expansion of real number s. For example, \pi can be represented as a continued fraction

\pi = 3.14159265... = 3+\frac{1}{7+\frac{1}{15+\frac{1}{1+\frac{1}{292+\frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{2+\frac{1}{1+\frac{1}{3+\frac{1}{1+\frac{1}{14+\frac{1}{2+\frac{1}{1}}}}}}}}}}}}}}

or \pi = \left [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3 ...\right].

Continued fractions have become more common in various other areas since the beginning of the twentieth century. For example, Robert M. Corless [2] examines the connection between theory of chaotic dynamical systems and continued fractions. It has also been used in computer algorithms for computing rational approximations to real numbers, as well as for solving Diophantine approximation of complex numbers [1] .

It turns out that complex numbers can also be represented as continued fractions, and, as such, falls between two Gaussian integers, and the unit is any divisor of z whose norm is 1.

The best method at the moment was devised by Asmus Schmidt. [1]

Let

\mathbf{Z}\left [ i \right ] = \left\{a + bi : a, b \in \mathbf{Z},b \geq 0 \right\} \cup \left\{ \infty\right\},

\mathbf{Z^{*}}\left [ i \right ]= \left \{ a+bi : a,b \in \mathbf{Z}, 0\leq a\leq 1, b\geq \left ( a-a^{2} \right )^{1/2} \right \}\cup \left \{ \infty \right \}.

The set \mathbf{Z}[i] , \mathbf{Z}^{*}[i] and their subdivisions into

\mathbf{Z}[i] = \mathbf{V_1}\cup \mathbf{V_2}\cup \mathbf{V_3}\cup \mathbf{E_1}\cup \mathbf{E_2}\cup \mathbf{E_3}\cup \mathbf{C}, and \mathbf{Z}^{*}[i] = \mathbf{V^{*}_1}\cup \mathbf{V^{*}_2}\cup \mathbf{V^{*}_3}\cup\mathbf{C^{*}}.

are shown in Fig. 1, Fig. 1*, respectively.

Figure 1, Figure 1*. Every boundary point occurring in Fig. 1 is properly equivalent to a real number, and that every boundary point occurring in Fig. 1* is improperly equivalent to a real number. [1]

(Note : all regions are bounded by straight lines or circles with radii 1/2 (or part thereof), and are supposed to be closed; \infty \in \mathbf{V_1},\mathbf{E_2},\mathbf{E_3},\mathbf{V^{*}_1}.)

The 8 matrices v_1, v_2, v_3, e_1, e_2, e_3, c, s are defined  as follows :

v_1= \begin{pmatrix}  1 & i\\  0 & 1  \end{pmatrix},  v_2= \begin{pmatrix}  1 & 0\\  -i & 1  \end{pmatrix},  v_3= \begin{pmatrix}  1-i & i\\  -i & 1+i  \end{pmatrix},

e_1= \begin{pmatrix}1 & 0\\ 1-i & i\end{pmatrix}, e_2= \begin{pmatrix}1 & -1+i\\ 0 & i \end{pmatrix}, e_3= \begin{pmatrix}i & 0\\ 0 & 1\end{pmatrix},

c = \begin{pmatrix}1 & -1+i\\ 1-i & i\end{pmatrix}, s = \begin{pmatrix}0 & -1\\ 1 & -1\end{pmatrix}.

For any invertible matrix M,

M= \begin{pmatrix}p & q\\ r & s\end{pmatrix}

with elements in C, let m denote the corresponding homographic map :

m:z \mapsto \frac{pz+q}{rz+s}

And \chi :z \mapsto \bar{z} denotes complex conjugation of C.

A homographic map m:z \mapsto (pz+q)/(rz+s) is called unimodular if p,q,r,s\in \mathbf{Z}\left [ i \right ] (the ring of Gaussian integers) and \mathrm{det}~m= ps-qr \in \mathfrak{U}= \left \{ \pm 1,\pm i \right \}. Notice that the determinant of a unimodular map is defined only as an element in the quotient group \mathfrak{U}/\mathfrak{U}^{2} consisting of the two elements \left \{ \pm 1 \right \}, \left \{ \pm i \right \}. A unimodular map m is called properly unimoduIar if  \mathrm{det}~m= \left \{ \pm 1 \right \} and improperly unimodular if \mathrm{det}~m= \left \{ \pm i \right \}.

An immediate consequence of these definitions is that every boundary point occurring in Fig. 1 is properly equivalent to a real number, and that every boundary point occurring in Fig. 1* is improperly equivalent to a real number.

A complex number, for example \mathrm{e}^i can be represented as a series of these matrices: c ~c ~v_3 ~c ~c ~v_3 ~v_3 ~v_3 ~c ~c ~v_3 ~v_3 ~v_3 ~v_3 ~v_3 ~c ~c and so on.  Multiplying them together would yield :

\begin{pmatrix}  1541-1037i & -40+1857i\\  -40-1857i & 1541+1037i  \end{pmatrix}

If the top and bottom are added up, the fraction \left(1501 + 820 i \right)/\left(1501 - 820 i\right) can be made, which approximately equals 0.5403023380 + 0.8414709642 i. e^i starts off 0.5403023059 + 0.8414709848 i.

The Asmus Schmidt method uses partitions to divide the complex plane into regions, then subregions, and so on, and in this way, each point is encoded by the sequence of regions to which it belongs. In the first generation :

Figure 2.  The first generation of Asmus Schmidt’s complex continued fraction method. (picture credite to Ed Pegg Jr., courtesy of MAA)

After that, each triangular region is divided into 4 parts, by adding a circle. In addition, each circle is divided into 8 regions, by adding 3 tangent circles.

Figure 3.  The third generation of Asmus Schmidt’s complex continued fraction method. (picture credite to Ed Pegg Jr., courtesy of MAA)

Here is a portion of fourth generation :

Figure 4.  The fourth generation of Asmus Schmidt’s complex continued fraction method. (picture credite to Ed Pegg Jr., courtesy of MAA)

Another interesting visualization on further successive generation was done by Mathematica software[7] in which seven matrices are used. Each use of these matrices divides the plane into seven parts as shown in the Figure 5.

Figure 5.  Sucessive generations of Asmus Schmidt’s complex continued fraction method (picture credite to Doug Hensley, at Wolfram Library Archive).

References :

[1] Asmus L. Schmidt, Diophantine Approximation of Complex Numbers, University of Copenhagen, Denmark.

[2] Robert M. Corless, Continued Fractions and Chaos, Dept. Applied Math, University of Western Ontario, Canada.

[3] Ed Pegg Jr., Gaussian Numbers, editorial Math Games, March 15, 2004, MAA.

[4] MathWorld, Continued Fractions, Pi Continued Fraction.

[5] W. F. Hammond, Continued Fractions and the Euclidean Algorithm, Department of Mathematics and Statistics, University at Albany.

[6] Wikipedia, Continued Fraction, Generalized continued fraction, Gaussian integer.

[7] Wolfram Library Archive, Complex Continued Fractions, picture download : PDF document.