샘플 01 1번 풀이
from pylab import *
for i in arange(0.0,2*pi,0.2):
t = arange(0.0, 2*pi,0.01)
x= cos(t)+cos(i)
y= sin(t)+sin(i)
plot(x,y)
show()
from pylab import *
for i in arange(0.0,2*pi,0.01):
t= arange(0.0,2*pi,0.1)
x=cos(t)+cos(i)
y=sin(t)+sin(i)
plot(x,y) # 들여쓰기 잘못도 치명적 오류
show()
from pylab import *
i = arange(0.0,2*pi,0.1)
for j in arange(0.0,2*pi,0.1):
x= 0.1*cos(i)+cos(j)
y= 0.1*sin(i)+sin(j)
plot(x,y)
show()
2번 풀이
# encoding:utf-8
from pylab import *
f = open("C:/logs.txt","r")
lines = f.readlines()
f.close()
aList = map(lambda a:a.split(),lines)
del aList[0]
nameList = map(lambda a:a[8],aList)
plot(map(lambda name:nameList.count(name),set(nameList)))
show()
3번 풀이
from pylab import *
t = arange(0.0, 5.0, 0.02)
a = np.exp(-t)+np.exp(-4*t)
plot(t, a,"r^")
b = np.exp(-t)*cos(sqrt(3)*t)+np.exp(-4*t)*sin(sqrt(3)*t)
plot(t, b,"bo")
c = cos(2*t)+sin(2*t)
plot(t, c,"b")
d = np.exp(-2*t)+t*np.exp(-2*t)
plot(t, d,"g+")
title('About as simple as it gets, folks')
grid(True)
show()
4번 풀이
from pylab import *
t = arange(0.0, 20.0, 0.02)
s = 2*(sin(t)/1 - sin(2*t)/2 + sin(3*t)/3 - sin(4*t)/4+sin(5*t)/5)
plot(t, s, linewidth=1.0)
title('About as simple as it gets, folks')
grid(True)
show()
샘플 01 1번 풀이
from pylab import *
t = arange(0.0, pi, 0.02)
plot(t,sin(6*t),"g")
plot(t,cos(6*t),"y")
s = sin(6*t)+cos(6*t)
plot(t, s, "r")
k = sin(6*t)*cos(6*t)
plot(t, k, "b")
title('sin, cos add & sin, cos mult')
grid(True)
show()
2번 풀이
from pylab import *
a=[[0,0],[3,5],[3,8]]
b=[[1,1],[3,6],[5,8]]
print(map(lambda x,y:sqrt((x[1]-y[1])**2+(x[0]-y[0])**2),a,b))
3번
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0., 10, 0.1)
i = 1+1j
print abs(i)
# log x and y axis
plt.loglog(t, abs(1j*t/((1j*t*1j*t)+1j*t+1.0)))
plt.grid(True)
plt.show()
4번
from pylab import *
import numpy as np
import matplotlib.pyplot as plt
t = arange(0.0, 0.05, 0.0001)
i = 100/(1+1j*4)
print angle(i)
It = imag(i*np.exp(1j*120*np.pi*t))
plot(t,It, "r")
plot(t,imag(100*np.exp(1j*120*np.pi*t)),"b")
show()