원주좌표계에서 이변수함수

    z = g(r, theta) = sin(r) / r = sin(sqrt(x^2 + y^2)) / sqrt(x^2 + y^2)

의 그래프를 그려보자. 이 함수의 그래프는 xz-평면에서 z = sin(x) / x 의 그래프를 그린 다음 z-축을 회전축으로 하여 일회전허면 얻어지는 곡면이다, z의 값은 theta 에 관하여는 상수이고, 오직 z-축 까지의 거리 r 에만 의존한다. 참고로, 이 이변수함수의 그래프는 Octave 의 로고

로도 쓰인다,


* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기





* 윈도우 XP 에서 wxMaxima 를 이용하여 그리기
** 명령 입력



** 위의 명령으로 별도의 창에 그려진 곡면





* Mac OS X Lion 에서 Grapher 를 이용하여 그리기





* 윈도우 XP 에서 Gnuplot 을 이용하여 그리기
** Gnuplot 소스
set term win
set samples 51, 51
set isosamples 21, 21
splot [-2*pi:2*pi][-2*pi:2*pi] sin(sqrt(x**2 + y**2))/sqrt(x**2 + y**2)


** 위의 명령으로 Gnuplot 이 그려준 곡면




* 윈도우 XP 에서 Octave 3.2.4 를 이용하하여 곡면 그리기
** Octave 소스
 tx = ty = linspace (-8, 8, 41)';
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r;
mesh (tx, ty, tz);



** 위의 명령으로 Octave 가 그려준 곡면




* Matplotlib 를 이용하여 곡면 그리기
** 파이썬 소스

#!/usr/bin/env python

from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt

# imports specific to the plots in this example
import numpy as np
from matplotlib import cm

# Twice as wide as it is tall.
fig = plt.figure(figsize=plt.figaspect(0.7))

#---- First subplot
ax = fig.add_subplot(111, projection='3d')
X = np.arange(-2*np.pi, 2*np.pi, 0.05)
Y = np.arange(-2*np.pi, 2*np.pi, 0.05)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R) / R
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
        linewidth=0, antialiased=False)
ax.set_zlim3d(-1.01, 1.01)

fig.colorbar(surf, shrink=0.5, aspect=10)

plt.show()



** 위의 소스를 실행시켜서 그린 곡면



 

Posted by Scripter
,
대학 1학년 미적분학 과정에서 극좌표를 배우는 시간이면 빠짐없이 등장하는 4엽장미 곡선(quadrifolium)을 그려보자.

일반적인 장미 곡선(rose or rhodonea curve)의 극방정식은

       r = a * cos( b theta )
       (단, 여기서 a 와 b 는 상수이고, r 과 theta 는 극좌표)

은 이다. 상수 a 의 값을 변경하면 장미의 크기가 변경되지만, 상수 b의 값을 변경하면 징미 잎의 개수가 변경된다, (특히 b 를 정수로 하면, 잎의 개수는 2b 개이다,) 그러므로 b = 2 로 하면 잎이 4개인 (네잎 클로버 모양의) 4엽장미 곡선(quadrifolium)이다.


즉, 4엽장미 곡선(quadrifolium)의 극방정식은

       r = cos( 2 theta )
       (단, 여기서 r 과 theta 는 극좌표)

이다. 이제 이 곡선을 여러가지 도구

           Mathematica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들을 이용하여 그리는 명령을 각각 알아보자.

 
* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기




* Mac OS X Lion  에서 wxMaxima 를 이용하여 4엽장미 곡선 그리기
** wxMaxima 창에서 그리기 명령 입력
    (주의: Mac 의 경우, draw 에 의한 그리기 명령은  옵션에 반드시 terminal=aquaterm 을 넣어주어야 그래프가 그려진다.)



** 위의 명령으로 별도의 창에 그려진 4엽장미 곡선




* Mac OS X Lion 에서 Grapher 를 이용하여 4엽장미 곡선 그리기




* Mac OS X Lion 에서 Gnuplot 을 이용하여 4엽장미 곡선 그리기
** Gnuplot 소스
set term aqua   # for Mac gnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 1600, 1600
set xzeroaxis linetype 0 linewidth 1.0
set yzeroaxis linetype 0 linewidth 1.0
set zzeroaxis linetype 0 linewidth 1.0
set xtics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set ytics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set title "Cardioid"
set trange [ 0.0 : 2*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
a = 1
b = 2
quadriFolium(teta) = a*cos(b*teta);
plot 0.5, 1, quadriFolium(t)



** Mac OS X Lion 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



** 위의 명령으로 Gnuplot 이 그려준 곡선




* 윈도우 XP 에서 Octave 를 이용하여 4엽장미 곡선 그리기
** Octave 소스
a = 1;
b = 2;
t = 0:0.005:2*pi;
polar(t, a*cos(b*t))
axis([-1.5, 1.5, -1.5, 1.5])



** 위의 명령으로 Octave 가 그려준 4엽장미 곡선





* 윈도우 XP 에서 Python 2.7 & Matplotlib 1.0.1 을 이용하여 극방정식의 4엽장미 곡선 그리기
** 파이썬 소스

#!/usr/bin/env python

"""
An example which plots the graph in polar coordinates.
         Plot a cardioid in polar coordinates.
"""
import matplotlib
import numpy as np
from matplotlib.pyplot import figure, show, rc, grid

# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
# ax = fig.add_axes([-2, -2, 2, 2], polar=True, axisbg='#d5de9c')

delta = 0.01
startAngle = 0.0
lastAngle = 2*np.pi
theta = np.arange(startAngle, lastAngle, 0.01)
a = 1
b = 2
r = a*np.cos(b*theta)
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(1.2)
grid(True)

ax.set_title("Quadrifolium", fontsize=16)
show()


 
** 위의 소스를 실행시켜서 그린 곡선

Posted by Scripter
,
대학 1학년 미적분학 시간에 배우는 심장형 곡선(cardioid) 

       r = 1 - cos( theta )
       (단, 여기서 r 과 theta 는 극좌표)

을 여러가지 도구

           Mathematica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들로 그리는 명령을 각각 알아보자.

 
* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기




* 윈도우 XP  에서 wxMaxima 를 이용하여 심장형 곡선 그리기
** wxMaxima 창에서 그리기 명령 입력



** 위의 명령으로 별도의 창에 그려진 심장형 곡선(cardioid)




* Mac OS X Lion 에서 Grapher 를 이용하여 심장형 곡선 그리기




* 윈도우 XP 에서 Gnuplot 을 이용하여 심장형 곡선 그리기
** Gnuplot 소스
set term win   # for Window wgnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 1600, 1600
set xzeroaxis linetype 0 linewidth 1.0
set yzeroaxis linetype 0 linewidth 1.0
set zzeroaxis linetype 0 linewidth 1.0
set xtics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set ytics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set title "Cardioid"
set trange [ 0.0 : 2*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
a = 1
b = 1
Cardioid(teta) = a - b*cos(teta);
plot 0.5, 1, Cardioid(t)



** 윈도우 XP 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



** 위의 명령으로 Gnuplot 이 그려준 곡선





* 윈도우 XP 에서 Octave 를 이용하여 그리기
** 극방정식의 심장형 곡선 그리기 (Octave 소스)
a = 1;
b = 1;
t = 0:0.005:2*pi;
polar(t, a - b*cos(t))
axis([-2.5, 0.5, -1.5, 1.5])


** Octave 실행 창에서 그리기 명령 입력



** 위의 명령으로 Octave 가 그려준 곡선





* Python 2.7 & Matplotlib 를 이용하여 극방정식의 심장형 곡선 그리기
** 파이썬 소스
#!/usr/bin/env python

"""
An example which plots the graph in polar coordinates.
         Plot a cardioid in polar coordinates.
"""

import matplotlib
import numpy as np
from matplotlib.pyplot import figure, show, rc, grid

# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
# ax = fig.add_axes([-2, -2, 2, 2], polar=True, axisbg='#d5de9c')

delta = 0.01
startAngle = 0.0
lastAngle = 2*np.pi
theta = np.arange(startAngle, lastAngle, 0.01)
a = 1
b = 1
r = a - b*np.cos(theta)
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.1)
grid(True)

ax.set_title("Cardioid", fontsize=20)
show()


 
** 위의 소스를 실행시켜서 그린 곡선


 

Posted by Scripter
,
lemniscate 는

       극방정식   r^2 = cos( 2 theta )
       또는 직교방정식 (x^2 + y^2)^2 = x^2 - y^2

으로 주어진다.  이 곡선은 철도 공사나 도로 공사시 곡선형 도로를 만들 때
원심력을 줄이기위한 방편으로 사용되기도 한다.

이제 이 곡선을 여러가지 도구

           Mathematica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들로 각각 그려보자.

 
* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기





* 윈도우 XP  에서 wxMaxima 를 이용하여 연주형 곡선 그리기
1) 직교방장식 (x^2 + y^2)^2 = x^2 - y^2 의 곡선



2) 극방정식 r^2 = cos(2 theta) 의 곡선
** 그리기 명령 입력



** 위의 명령으로 별도의 창에 그려진 연주형 곡선(lemniscate)





* Mac OS X Lion 에서 Grapher 를 이용하여 그리기
1) 직교방정식의 연주형 곡선 그리기




2) 극방정식의 연주형 곡선 그리기




* Gnuplot 을 이용하여 연주형 곡선 그리기
1) 직교방정식의 연주형 곡선 그리기
** 윈도우 XP 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



** 위의 명령으로 Gnuplot 이 그려준 곡선




1) 극방정식의 연주형 곡선 그리기
** Gnuplot 소스
set term win   # for Window wgnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 1600, 1600
set xzeroaxis linetype 0 linewidth 1.0
set yzeroaxis linetype 0 linewidth 1.0
set zzeroaxis linetype 0 linewidth 1.0
set xtics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set ytics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set title "Lemniscate"
set trange [ 0.0 : 2*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
Lemniscate(x) = sqrt(cos(2*x))
plot 1, 0.5, Lemniscate(t)



** 윈도우 XP 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



** 위의 명령으로 Gnuplot 이 그려준 곡선





* Octave 를 이용하여 그리기
 1) 직교방정식의 연주형 곡선 그리기 (소스)
ezplot (@(x, y) (x .^ 2 + y .^ 2).^2 - x .^ 2 + y .^ 2, 2000)

** 위의 명령으로 Octave 가 그려준 곡선




2-1) 극방정식의 연주형 곡선 그리기 (소스)
t = 0:0.005:2*pi;
polar(t, sqrt(cos(2*t)));

** 위의 명령으로 Octave 가 그려준 곡선




2-1) 극방정식의 연주형 곡선 그리기 (소스)
t = 0:0.005:2*pi;
polar(t, sqrt(cos(2*t)));

** 위의 명령으로 Octave 가 그려준 곡선





* Matplotlib 를 이용하여 그리기
1) 직교방정식의 원주형 곡선 그리기
** 파이썬 소스

#!/usr/bin/env python

"""
An example which plots the graph of an implicit function.
         Plot the lemniscate.
"""

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

delta = 0.01
x = np.arange(-1.1, 1.1, delta)
y = np.arange(-1.1, 1.1, delta)
X, Y = np.meshgrid(x, y)
Z = (X**2 + Y**2)**2 - X**2 + Y**2

# Set negative contours to be solid iine.
matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
plt.figure()
CS = plt.contour(X, Y, Z, 1, colors='k')
plt.title("Lemniscate")

plt.show()




** 위의 소스를 실행시켜서 그린 그래프



2) 극방정식의 원주형 곡선 그리기
** 파이썬 소스

#!/usr/bin/env python

"""
An example which plots the graph of an implicit function.
         Plot the lemniscate.
"""

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

delta = 0.01
x = np.arange(-1.1, 1.1, delta)
y = np.arange(-1.1, 1.1, delta)
X, Y = np.meshgrid(x, y)
R = np.sqrt(X**2 + Y**2)
T = np.arctan(Y/X)
Z = R**2 - np.cos(2*T)

# Set negative contours to be solid iine.
matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
plt.figure()
CS = plt.contour(X, Y, Z, 1, colors='k')
plt.title("Lemniscate")

plt.show()



 
** 위의 소스를 실행시켜서 그린 그래프




 

Posted by Scripter
,
함수

    g(x) = x sin(1/x)

 의 그래프를 그려보자. 이 함수는 x = 0 에서 정의되어 있지 않지만, f(0) 의 값을  극한값 lim_{x -> 0} x sin(1/x) = 0 으로 정해주면 이 함수는 x = 0 에서 연속함수가 된다. 이러한(이와 같이 함수값만 다시 잘 정해주면 연속이 되는) 불연속점 x = 0 을 이 함수의 제거가능 특이점(removable singularity)이라고 한다.


* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기





* Mac OS X Lion  에서 wxMaxima 를 이용하여 그리기




* Mac OS X Lion 에서 Grapher 를 이용하여 그리기




* Gnuplot 을 이용하여 그리기
** Mac OS X Lion 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면




** 위의 명령으로 Gnuplot 이 그려준 그래프





* Octave 를 이용하여 그리기 (소스)
x = -4:0.01:4;
plot(x, x .* sin(1 ./ x), 1, [-1, 1.5])


** 윈도우용 Octave 3.2.4 를 실행하여 그리기 명령을 입력한 장면



** 위의 명령으로 Octave 가 그려준 그래프






* Matplotlib 를 이용하여 그리기
** 파이썬 소스

#!/usr/bin/env python

import math
from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines


def make_xaxis(ax, yloc, offset=0.05, **props):
    xmin, xmax = ax.get_xlim()
    locs = [loc for loc in ax.xaxis.get_majorticklocs()
            if loc>=xmin and loc<=xmax]
    tickline, = ax.plot(locs, [yloc]*len(locs),linestyle='',
            marker=lines.TICKDOWN, **props)
    axline, = ax.plot([xmin, xmax], [yloc, yloc], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)
    for loc in locs:
        ax.text(loc, yloc-offset, '%1.1f'%loc,
                horizontalalignment='center',
                verticalalignment='top')

def make_yaxis(ax, xloc=0, offset=0.05, **props):
    ymin, ymax = ax.get_ylim()
    locs = [loc for loc in ax.yaxis.get_majorticklocs()
            if loc>=ymin and loc<=ymax]
    tickline, = ax.plot([xloc]*len(locs), locs, linestyle='',
            marker=lines.TICKLEFT, **props)
    axline, = ax.plot([xloc, xloc], [ymin, ymax], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)

    for loc in locs:
        ax.text(xloc-offset, loc, '%1.1f'%loc,
                verticalalignment='center',
                horizontalalignment='right')


fig = plt.figure(facecolor='white')
ax = fig.add_subplot(111, frame_on=False)

props = dict(color='black', linewidth=2, markeredgewidth=2)
ax.axison = False
ax.set_xlim(-4, 4)
ax.set_ylim(-1, 2)
make_xaxis(ax, 0, offset=0.2, **props)
make_yaxis(ax, 0, offset=0.5, **props)

x = arange(-4.0, -0.01, 0.01)
a = x * sin(1 / x)
a1 = x
a2 = -x
ax.plot(x, a,'b-',  x, a1,'k--',  x, a2,'k--')

t = arange(0.01, 4.0, 0.01)
b = t * sin(1 / t)
b1 = t
b2 = -t
ax.plot(t, b,'b-',  t, b1,'k--',  t, b2,'k--')

grid(True)
xlabel('----> x')
ylabel('----> y')

title('The graph of y = x sin(1/x)')

# plot the colored markers on the graph
# ax.plot(t, b, 'd', markersize=3, markerfacecolor='blue')
# ax.plot(x, a, 'd', markersize=3, markerfacecolor='red')

# set the rectangular range to be viewed.
plt.axis([-4, 4, -1.0, 1.5])

plt.show()



** 위의 소스를 실행시켜서 그린 그래프




 

Posted by Scripter
,
함수

    f(x) = sin(x) / x

 의 그래프를 그려보자. 이 함수는 x = 0 에서 정의되어 있지 않지만, f(0) 의 값을  극한값 lim_{x -> 0} sin(x) / x = 1 로 정해주면 이 함수는 x = 0 에서 연속함수가 된다. 이러한(이와 같이 함수값만 다시 잘 정해주면 연속이 되는) 불연속점 x = 0 을 이 함수의 제거가능 특이점(removable singularity)이라고 한다.


* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기





* Mac OS X Lion  에서 wxMaxima 를 이용하여 그리기




* Mac OS X Lion 에서 Grapher 를 이용하여 그리기




* Gnuplot 을 이용하여 그리기
** Mac OS X Lion 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면




** 위의 명령으로 Gnuplot 이 그려준 그래프






* Octave 를 이용하여 그리기 (소스)
 x = -20:0.05:20;
 plot(x, sin(x)./x, 1, [-1, 2])   # 나누그 연산자가 / 가 아니고 ./ 임에 유의한다.


** 윈도우용 Octave 3.2.4 를 실행하여 그리기 명령을 입력한 장면



** 위의 명령으로 Octave 가 그려준 그래프






* Matplotlib 를 이용하여 그리기
** 파이썬 소스

#!/usr/bin/env python

import math
from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines


def make_xaxis(ax, yloc, offset=0.05, **props):
    xmin, xmax = ax.get_xlim()
    locs = [loc for loc in ax.xaxis.get_majorticklocs()
            if loc>=xmin and loc<=xmax]
    tickline, = ax.plot(locs, [yloc]*len(locs),linestyle='',
            marker=lines.TICKDOWN, **props)
    axline, = ax.plot([xmin, xmax], [yloc, yloc], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)
    for loc in locs:
        ax.text(loc, yloc-offset, '%1.1f'%loc,
                horizontalalignment='center',
                verticalalignment='top')

def make_yaxis(ax, xloc=0, offset=0.05, **props):
    ymin, ymax = ax.get_ylim()
    locs = [loc for loc in ax.yaxis.get_majorticklocs()
            if loc>=ymin and loc<=ymax]
    tickline, = ax.plot([xloc]*len(locs), locs, linestyle='',
            marker=lines.TICKLEFT, **props)
    axline, = ax.plot([xloc, xloc], [ymin, ymax], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)

    for loc in locs:
        ax.text(xloc-offset, loc, '%1.1f'%loc,
                verticalalignment='center',
                horizontalalignment='right')


fig = plt.figure(facecolor='white')
ax = fig.add_subplot(111, frame_on=False)

props = dict(color='black', linewidth=2, markeredgewidth=2)
ax.axison = False
ax.set_xlim(-20, 20)
ax.set_ylim(-1, 2)
make_xaxis(ax, 0, offset=0.2, **props)
make_yaxis(ax, 0, offset=0.5, **props)

x = arange(-20.0, -0.01, 0.01)
a = sin(x) / x
a1 = - 1 / x
ax.plot(x, a,'b-',  x, a1,'k--')

t = arange(0.01, 20.0, 0.01)
b = sin(t) / t
b1 = 1 / t
ax.plot(x, a,'b-',  x, a1,'k--', t, b,'b-',  t, b1,'k--')

grid(True)
xlabel('----> x')
ylabel('----> y')

title('The graph of y = sin(x) / x')

# plot the colored markers on the graph
# ax.plot(t, b, 'd', markersize=3, markerfacecolor='blue')
# ax.plot(x, a, 'd', markersize=3, markerfacecolor='red')

# set the rectangular range to be viewed.
plt.axis([-20, 20, -1.0, 2.0])

plt.show()



** 위의 소스를 실행시켜서 그린 그래프





 
Posted by Scripter
,

사이클로이드(cycloid)의 직교방정식(직교좌표에 의한 방정식)은

             x = a arccos(1 - y/a) - sqrt(2ay - y^2)

이다. 이 직교방정식을 이용하여 사이클로이드를 그려보자.


* 윈도우 XP 에서 Mathematica 8 을 이용하여 그린 사이클로이드(cycloid):




* Mac OS X Lion 에서 Maxima 5.25.0 을 이용하여 그린 직교방정식의 사이클로이드

 

 

* Mac OS X Lion 에서 직교방정식의 사이클뢰드 그리기
   (사이클로이드를 직교방정식으로 그리기 위한 gnuplot 소스)

set term aqua
set xrange[-1:9] 
set yrange[-1:4]
set isosamples 250
set view map
unset surface
set hidden3d
set key outside
set contour base
set title "cycloid by plotting contour"
splot x - acos(1 - y) + sqrt(2*y - y**2) 


 

** Mac OS X Lon 에서 Gnuplot 을 실행시킨 모습 

 


*** Gnuplot 이 그려준 직교방정식에 의한 사이클로이드

 



* Mac OS X Lion 에서 Grapher 를 이용하여 직교방정식의 사이클로이드:

 

 

* 윈도우 XP 에서 Python 2.7 & matplotlib 1.0.1 을 이용하여 그린 그래프:
** 파이썬 소스

#!/usr/bin/env python

import math
from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines


def make_xaxis(ax, yloc, offset=0.05, **props):
    xmin, xmax = ax.get_xlim()
    locs = [loc for loc in ax.xaxis.get_majorticklocs()
            if loc>=xmin and loc<=xmax]
    tickline, = ax.plot(locs, [yloc]*len(locs),linestyle='',
            marker=lines.TICKDOWN, **props)
    axline, = ax.plot([xmin, xmax], [yloc, yloc], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)
    for loc in locs:
        ax.text(loc, yloc-offset, '%1.1f'%loc,
                horizontalalignment='center',
                verticalalignment='top')

def make_yaxis(ax, xloc=0, offset=0.05, **props):
    ymin, ymax = ax.get_ylim()
    locs = [loc for loc in ax.yaxis.get_majorticklocs()
            if loc>=ymin and loc<=ymax]
    tickline, = ax.plot([xloc]*len(locs), locs, linestyle='',
            marker=lines.TICKLEFT, **props)
    axline, = ax.plot([xloc, xloc], [ymin, ymax], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)

    for loc in locs:
        ax.text(xloc-offset, loc, '%1.1f'%loc,
                verticalalignment='center',
                horizontalalignment='right')


fig = plt.figure(facecolor='white')
ax = fig.add_subplot(111, frame_on=False)

props = dict(color='black', linewidth=2, markeredgewidth=2)
ax.axison = False
ax.set_xlim(-2, 3*pi)
ax.set_ylim(-1, 5)
make_xaxis(ax, 0, offset=0.2, **props)
make_yaxis(ax, 0, offset=0.5, **props)

y = arange(0.0, 2., 0.01)
x = arccos(1 - y) - sqrt(2*y - y**2)
ax.plot(x, y, 'b-')

grid(True)
xlabel('----> x')
ylabel('----> y')

title('A cycloid : the graph of x = arccos(1 - y) - sqrt(2y -y^2)')

# plot the colored markers on the graph
# ax.plot(t, b, 'd', markersize=3, markerfacecolor='blue')
# ax.plot(x, a, 'd', markersize=3, markerfacecolor='red')

# set the rectangular range to be viewed.
plt.axis([-2, 3*pi, -1.0, 5.0])

plt.show()






** 위의 소스를 실행시켜서 그린 그래프


 

Posted by Scripter
,

매개방정식을 공부할 때면 빠지지 않고 등장하는 사이클로이드(cycloid)

             x = a (theta  - sin(theta))
            y = a(1 - cos(theta)) 
               where  a is the radius of rolling circle and theta is the rotated angle

를 그려보자.

[참고  자료 1] Maxima 로 동작하는 사이클로이드 애니메이션
[참고 자료 2] SVG 로 만든 사이클로이드 애니메이션 

* 윈도우 XP 에서 Mathematica 8 을 이용하여 그린 사이클로이드(cycloid):





* 윈도우 XP 에서 Maxima 5.25.0 을 이용하여 매개곡선으로 사이클로이드 그리기



*** wxplot2d 대신에 plot2d 를 사용하면 뱔도의 창에 그려준다.
     (wxMaxima 대신에 xMaxima 를 사용하였다)



** 위의 명령으로 xMaxima 가 별도의 창에 그려준 매개곡선




 

* 윈도우 XP 에서 윈도우 용 Gnuplot 을 이용하여 그린 함수의 그래프:
(* 윈도우 용 Gnuplot 다운로드: http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/ *)

** 사이클로이드를 매개곡선으로 그리기 위한 gnuplot 소스

set term win
set parametric
set dummy t
set samples 1600
set trange [0 : 3.5*pi]
set xrange [-1 : 5*pi]
set yrange [-2 : 5]
set title "cycloid"
plot t - sin(t), 1 - cos(t)



** 윈도우 XP 에서 윈도우용 Gnuplot(wgnuplot.exe)을 실행시킨 모습 




*** Gnuplot 이 그려준 사이클로이드




* Mac OS X Lion 에서 Grapher 를 이용하여 그린 사이클로이드:

 

 

* 윈도우 XP 의 Python 2.7 에 matplotlib 1.0.1 을 (모두 32비트 용으로) 설치하여 파이썬 소스로 그린 음함수의 그래프:

#!/usr/bin/env python

"""
An example which plots the parametirized curve.
         Plot a cycloid..
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure, show, rc, title
import matplotlib.lines as mlines


# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
fig = figure(figsize=(8,8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=False, axisbg='#d5de9c')

plt.axvline(x=0, color='black')
plt.axhline(y=0, color='black')
plt.axvline(x=np.pi, color='silver')
plt.axvline(x=2*np.pi, color='silver')
plt.axvline(x=3*np.pi, color='silver')
plt.axvline(x=4*np.pi, color='silver')
plt.axhline(y=2, color='silver')

t = np.arange(0.0, 3.5*np.pi, 0.05)

a = 1
x = a*(t - np.sin(t))
y = a*(1 - np.cos(t))

ax.set_xlim(-0.5, 4*np.pi)
ax.set_ylim(-1, 4)
ax.plot(x, y, color='#ee8d18', lw=3, label='cycloid')
ax.legend()

title("cycloid")
show()




 

#!/usr/bin/env python

"""
An example which plots the parametirized curve.
         Plot the Descartes' folium.
"""

import numpy as np
from matplotlib.pyplot import figure, show, rc, title

# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
fig = figure(figsize=(8,8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=False, axisbg='#d5de9c')


t = np.arange(0.0, 27.0, 0.05)
x =3*t/(1 + t**3)
y =3*t**2/(1 + t**3)
ax.plot(x, y, color='#ee8d18', lw=3, label='a line')
ax.legend()

t = np.arange(-18, -1.15, 0.05)
x =3*t/(1 + t**3)
y =3*t**2/(1 + t**3)
ax.plot(x, y, color='#ee8d18', lw=3, label='a line')

t = np.arange(-0.82, 0.01, 0.05)
x =3*t/(1 + t**3)
y =3*t**2/(1 + t**3)
ax.plot(x, y, color='#ee8d18', lw=3, label='a line')
# ax.legend()

title("Descartes' folium")
show()


(* 위의 소스는 수정 없이 윈도우 7 의 Python 3.2 64bit 에 matplotlib 1.1.0 64bit 를 설치하여 실행해도 된다 *)


 

Posted by Scripter
,

지수함수 y = exp(1/x) 의 그래프 그리기

참고로 이 함수는 두 함수 f(x) = 1/x 과 g(x) = exp(x)  의 합성함수이다.
 


* 윈도우 XP 에서 Mathematica 8 을 이용하여 그린 함수의 그래프:




* 윈도우 7 에서 Mathematica 8 을 이용하여 그린 함수의 그래프:




* Mac OS X Lion 에서 Maxima 5.25.0 을 이용하여 지수함수의 그래프를 그리기 위한 명령



* 위의 명령으로 별도의 창에 그려진 지수 함수 y = exp(1/x)  의 그래프





* Mac OS X Lion 에서 Gnuplot 을 이용하여 지수함수 y = exp(1/x) 의 그래프 그리기:

gnuplot> set term aqua

gnuplot> set xzeroaxis linetype 0 linewidth 1.000

gnuplot> set yzeroaxis linetype 0 linewidth 1.000

gnuplot> set xtics axis in scale 1,0.5 offset character 0, 0, 0 autofreq 

gnuplot> set ytics axis in scale 1,0.5 offset character 0, 0, 0 autofreq 

gnuplot> set yrange [ -10.0 : 10.0 ] noreverse nowriteback      

gnuplot> set xrange [ -10.0 : -0.01 ] noreverse nowriteback                

gnuplot> plot exp(1/x), 1




* 위의 명령으로 그려진 지수함수 y = exp(1/x) 의 그래프 중 좌측 반쪽:




* 우측 반쪽을 그리기 위한 Gnuplot 명령:

gnuplot> 
set xrange [ 0.01 : 10.0 ] noreverse nowriteback

gnuplot> plot exp(1/x), 1



* 위의 명령으로 그려진 지수함수 y = exp(1/x) 의 그래프 중 우측 반쪽:




* 윈도우 XP 의 Python 2.7 에 matplotlib 1.0.1 을 (모두 32비트 용으로) 설치하여 그린 지수함수 y = exp(1/x) 의 그래프:

#!/usr/bin/env python

import math
from pylab import *
import matplotlib.pyplot as plt
import matplotlib.lines as lines


def make_xaxis(ax, yloc, offset=0.05, **props):
    xmin, xmax = ax.get_xlim()
    locs = [loc for loc in ax.xaxis.get_majorticklocs()
            if loc>=xmin and loc<=xmax]
    tickline, = ax.plot(locs, [yloc]*len(locs),linestyle='',
            marker=lines.TICKDOWN, **props)
    axline, = ax.plot([xmin, xmax], [yloc, yloc], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)
    for loc in locs:
        ax.text(loc, yloc-offset, '%1.1f'%loc,
                horizontalalignment='center',
                verticalalignment='top')

def make_yaxis(ax, xloc=0, offset=0.05, **props):
    ymin, ymax = ax.get_ylim()
    locs = [loc for loc in ax.yaxis.get_majorticklocs()
            if loc>=ymin and loc<=ymax]
    tickline, = ax.plot([xloc]*len(locs), locs, linestyle='',
            marker=lines.TICKLEFT, **props)
    axline, = ax.plot([xloc, xloc], [ymin, ymax], **props)
    tickline.set_clip_on(False)
    axline.set_clip_on(False)

    for loc in locs:
        ax.text(xloc-offset, loc, '%1.1f'%loc,
                verticalalignment='center',
                horizontalalignment='right')


fig = plt.figure(facecolor='white')
ax = fig.add_subplot(111, frame_on=False)

props = dict(color='black', linewidth=2, markeredgewidth=2)
ax.axison = False
ax.set_xlim(-10, 10)
ax.set_ylim(-1, 10)
make_xaxis(ax, 0, offset=0.2, **props)
make_yaxis(ax, 0, offset=0.5, **props)

x = arange(-10.0, -0.01, 0.01)
a = exp(1/x)
a1 = 0*x + 1

t = arange(0.01, 10.0, 0.01)
b = exp(1/t)
b1 = 0*x + 1
ax.plot(x, a,'b-',  x, a1,'k--',  t, b, 'b-',  t, b1, 'k--')

grid(True)
xlabel('----> x')
ylabel('----> y')

title('The graph of y = exp(1/x)')

# plot the colored markers on the graph
# ax.plot(t, b, 'd', markersize=3, markerfacecolor='blue')
# ax.plot(x, a, 'd', markersize=3, markerfacecolor='red')

# set the rectangular range to be viewed.
plt.axis([-10, 10, -1.0, 10.0])

plt.show()


(* 위의 소스는 수정 없이 윈도우 7 의 Python 3.2 64bit 에 matplotlib 1.1.0 64bit 를 설치하여 실행해도 된다 *)







* 윈도우 XP의 Python 2.7 & Tkinter 환경에서 지수함수 y = exp(1/x) 를 그려주는 파이썬 소스:

#! /usr/local/bin/python    <- The UNIX she-bang
# coding: MS949

#  Filename: seventhGraph.py
#
#  2011/09/10 Sat.    Modified by PHKim
#
# See: http://www.schockwellenreiter.de/pythonmania/pybutt.html

import Tkinter
import Canvas
import math    # for the exp function
import sys           # for sys.exit(0)   
from Tkconstants import *


class SeventhExponentialGraph:
   def __init__(self, master = None):
   self.canvas = Tkinter.Canvas(master, relief = RIDGE, bd = 2, bg = "white",
         width = 400, height = 400)
   self.canvas.pack()
  
   self.button = Tkinter.Button(master, text = " Draw ", command = self.draw)
   self.button.pack(side = BOTTOM, pady = 4)

   def make_xaxis(self, startx, endx, yloc, initx, deltax, offset=1, gap=20):
           i = initx
           px =startx
           while px < endx:
          self.canvas.create_line(px, yloc-3, px, yloc + 3, fill='black', width=1)
          if i != 0:
                   self.canvas.create_text(px, yloc-3 + offset + 12, text="%d" % i, fill='magenta')
          else:
                   self.canvas.create_text(px - 6, yloc-3 + offset + 12, text="%d" % i, fill='magenta')
               i = i + deltax
               px = px + gap

   def make_yaxis(self, starty, endy, xloc, inity, deltay, offset=-1, gap=20):
           i = inity
           py =starty
           while py < endy:
          self.canvas.create_line(xloc-3, py, xloc+3, py, fill='black', width=1)
          if i != 0:
              self.canvas.create_text(xloc-3 + offset + 2, py, text="%d" % i, fill='darkgreen')
               i = i + deltay
               py = py + gap

   def draw(self):
   self.canvas.create_line(0, 200, 440, 200, fill='black', width=2)
   self.canvas.create_line(200, 0, 200, 440, fill='black', width=2)
   self.canvas.create_line(0, 200-20, 440, 200-20, fill='gray', width=1)

   self.make_xaxis(0, 400, 200, -10, 1, 0.05, 20)
   self.make_yaxis(0, 400, 200, -10, 1, -10, 20)

   delta = 0.01
   t  = -10.0
   while t <= 0.01:
       # Draw the left part in the second quadrant
       x = t
       y = math.exp(1/x)
       xx = (x*20) + 200  # 20 pixel is the unit 1
       yy =  200 -  (y*20)              # 400 x 400 is the size of the drawing region
       if (t== -10.0):
       Canvas.Line(self.canvas, xx, yy, xx, yy, fill="blue", width=2)
       else:
       Canvas.Line(self.canvas, xOld, yOld, xx, yy, fill="blue", width=2)
       self.canvas.update_idletasks()
       xOld = xx
       yOld = yy
       t = t + delta

   delta = 0.01
   t  = 0.01
   while t <= 10+0.1:
       # Draw the right part in the first quadrant
       x = t
       y = math.exp(1/x)
       xx = (x*20) + 200  # 20 pixel is the unit 1
       yy =  200 -  (y*20)              # 400 x 400 is the size of the drawing region
       if (t== -10.0):
       Canvas.Line(self.canvas, xx, yy, xx, yy, fill="blue", width=2)
       else:
       Canvas.Line(self.canvas, xOld, yOld, xx, yy, fill="blue", width=2)
       self.canvas.update_idletasks()
       xOld = xx
       yOld = yy
       t = t + delta

   self.button.config(text = " Quit ", command = self.exit)
   self.canvas.update_idletasks()

   def exit(self):
   sys.exit(0)

if __name__ == "__main__":
   root = Tkinter.Tk()
   root.title("The curve of y = exp(1/x)")
 
   SeventhExponentialGraph(root)
   root.mainloop()





* 위의 소스를 실행하여 그려진 함수 y = exp(1/x) 의 그래프



Posted by Scripter
,

나비 모양의 곡선을 그려주는 극빙정식(polar equation):
           r = exp(cos(t)) - 2*cos(4*t) + (sin(t/12))^5 

[참고] 
  1.  Fay, Temple H. (May 1989). "The Butterfly Curve". Amer. Math. Monthly 96 (5): 442–443. doi:10.2307/2325155. JSTOR 2325155.
  2. SVG 로 만든 나비 곡선



* 윈도우 XP 에서 Mathematica 8 을 이용하여 그린 나비 모양의 곡선:





* 윈도우 XP 에서 Maxima 5.25.0 을 이용하여 극곡선을 그리는 명령





** 위의 명령으로 Maxima 가 별도의 창에 그려준 나비 모양의 곡선



 

* 윈도우 XP 에서 윈도우 용 Gnuplot 을 이용하여 그린 함수의 그래프:
(* 윈도우 용 Gnuplot 다운로드: http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/ *)

** 나비 모양의 극곡선을 그리는 gnuplot 소스

set term win   # for Window wgnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 800, 800
set xzeroaxis linetype 0 linewidth 1.000
set yzeroaxis linetype 0 linewidth 1.000
set zzeroaxis linetype 0 linewidth 1.000
set xtics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set ytics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set title "Butterfly"
set trange [ 0.00000 : 12*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
butterfly(x)=exp(cos(x))-2*cos(4*x)+sin(x/12)**5
plot 1, 2, 3, 4, 5, butterfly(t - pi/2)



** Gnuplot 이 그려준 곡선 





* Mac OS X Lion 에서 Grapher 를 이용하여 그린 나비 모양의 곡선:

 

 

* 윈도우 XP 의 Python 2.7 에 matplotlib 1.0.1 을 (모두 32비트 용으로) 설치하여 파이썬 소스로 그린 나비 모양의 극곡선:

#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np

theta = np.arange(0., 48., 1./360.)*np.pi
r = np.exp(np.cos(theta)) - 2*np.cos(4*theta) + np.sin(theta/12)**5
plt.polar(theta + np.pi/2, r);

plt.thetagrids(range(45, 360, 90));
plt.rgrids(np.arange(1.0, 6.1, 1), angle=0);

plt.show()



(* 위의 소스는 수정 없이 윈도우 7 의 Python 3.2 64bit 에 matplotlib 1.1.0 64bit 를 설치하여 실행해도 된다 *)


 


* 윈도우 XP 에서 Tkinter 를 이용하여 나비 모양의 극곡선을 그리는 파이썬 소스:

#! /usr/local/bin/python    <- The UNIX "pound bang hack" (auch she-bang).
# coding: MS949

#                              auf dem Mac bedeutunglos :-)
#  Filename: butterfly.py
#  ⓒ 1999 by Jorg Kantel
#
#  2011 Modified by PH Kim
#
# See: http://www.schockwellenreiter.de/pythonmania/pybutt.html

import Tkinter
import Canvas
import math    # fur die Sinus- und Kosinus-Funktionen
import sys           # fur sys.exit(0)   
from Tkconstants import *


class Butterfly:
   def __init__(self, master = None):
   self.canvas = Tkinter.Canvas(master, relief = RIDGE, bd = 2, bg = "white",
         width = 400, height = 400)
   self.canvas.pack()
  
   self.button = Tkinter.Button(master, text = " Draw ", command = self.draw)
   # Der Button soll nicht am unteren Rand "kleben", daher werden oben und
   # unten vier Pixel Rand angefugt.
   self.button.pack(side = BOTTOM, pady = 4)

   def draw(self):
   self.canvas.create_oval(160, 160, 240, 240, outline="black", width=1)
   self.canvas.create_oval(120, 120, 280, 280, outline="black", width=1)
   self.canvas.create_oval(80, 80, 320, 320, outline="black", width=1)
   self.canvas.create_oval(40, 40, 360, 360, outline="black", width=1)
   self.canvas.create_oval(0, 0, 400, 400, outline="black", width=1)
   theta  = 0.0
   while theta < 75.39:
       r = math.exp(math.sin(theta)) - 2*math.cos(4*theta) + (math.sin((2*theta - math.pi)/24))**5
       # aus Polarkoordinaten konvertieren:
       x = r*math.cos(theta)
       y =r*math.sin(theta)
       xx = (x*40) + 200  # auf Canvas-Große skalieren
       yy =  400 -  ((y*40) + 200)     # 400 is height of the region (Modified)
       if (theta == 0.0):
       Canvas.Line(self.canvas, xx, yy, xx, yy, fill="blue")
       else:
       Canvas.Line(self.canvas, xOld, yOld, xx, yy, fill="blue")
       self.canvas.update_idletasks()
       xOld = xx
       yOld = yy
       theta = theta + 0.01

   self.button.config(text = " Quit ", command = self.exit)
   self.canvas.update_idletasks()
   self.button.config(text = " Quit ", command = self.exit)

   def exit(self):
   sys.exit(0)

if __name__ == "__main__":
   # Dies ist nur, damit der Titel angezeigt wird ;-)
   root = Tkinter.Tk()
   # root.title("Butterfly Curve")
   root.title("Fay's Butterfly Curve")
 
   # Erzeuge eine neue Instanz unserer Schmetterlingsklasse ...
   butterfly = Butterfly(root)
   # ... und bringe sie zum Laufen.
   root.mainloop()






* 위의 소스를 실행시켜서 그린 나비 모양의 극곡선:




 

Posted by Scripter
,