코딩 수학

sympy ¸ðµâÀ» ºÒ·¯¿À°í, »ç¿ëÇÒ ±âÈ£ º¯¼ö¸¦ ¼±¾ðÇÑ´Ù. ¸ËÇ÷Ը³ ¸ðµâÀ» ºÒ·¯¿Â´Ù.

In [1]:
from sympy import *
init_printing()          

x, y, z = symbols('x y z')

%matplotlib inline 

이차함수

ÀÌÂ÷ÇÔ¼ö $y=x^2+2x-2$ ÀÇ ±×·¡ÇÁ¿Í Á÷¼± $y=x+1$ ¸¦ ±×¸°´Ù.

In [2]:
plot( x**2+2*x-2, x+1, xlim=(-6,6), ylim=(-4,4) )
Out[2]:
<sympy.plotting.plot.Plot at 0x1944ef0>

$x$ Ãà°ú $y$ ÃàÀÇ ¹üÀ§¸¦ ¼³Á¤Çϱâ À§ÇÏ¿©, xlim °ú ylim ÀÎÀÚ¸¦ »ç¿ëÇÏ¿´´Ù.

ÀÌÂ÷¹æÁ¤½Ä $x^2+2x-2=x+1$ ÀÇ ±ÙÀ» ±¸ÇÏ¿©, µÎ ±×·¡ÇÁ°¡ ¸¸³ª´Â Á¡À» ã´Â´Ù.

In [3]:
solve( Eq( x**2 + 2*x - 2, x + 1 ), x )
Out[3]:
$$\left [ - \frac{1}{2} + \frac{\sqrt{13}}{2}, \quad - \frac{\sqrt{13}}{2} - \frac{1}{2}\right ]$$

À§ °á°úÀÇ ¼öÄ¡°ªÀ» ±¸ÇÑ´Ù.

In [4]:
[ N( _[0] ), N( _[1] ) ]
Out[4]:
$$\left [ 1.30277563773199, \quad -2.30277563773199\right ]$$

유리함수 (분수함수)

´ÙÀ½ ºÐ¼öÇÔ¼öÀÇ ±×·¡ÇÁ¸¦ ±×¸°´Ù.

$$y= \frac 1 {x-1} -2 $$

In [5]:
plot( 1/(x-1) - 2, xlim=(-9,9), ylim=(-6,6) )
Out[5]:
<sympy.plotting.plot.Plot at 0x3e0ab50>

무리함수

¹«¸®ÇÔ¼öÀÇ ±×·¡ÇÁ¸¦ ±×¸°´Ù.

$y= \sqrt {2x+4} + 1 $

In [6]:
plot( sqrt( 2*x + 4 ) + 1 )
Out[6]:
<sympy.plotting.plot.Plot at 0x7c68250>