함수

    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
,