시험문제

Professor Ho's Wiki Site

샘플 01 1번 풀이

  1. from pylab import *
  2. for i in arange(0.0,2*pi,0.2):
  3.  t = arange(0.0, 2*pi,0.01)
  4.  x= cos(t)+cos(i)
  5.  y= sin(t)+sin(i)
  6.  plot(x,y)
  7. show()
  8.  
  9. from pylab import *
  10. for i in arange(0.0,2*pi,0.01):
  11.  t= arange(0.0,2*pi,0.1)
  12.  x=cos(t)+cos(i)
  13.  y=sin(t)+sin(i)
  14. plot(x,y) # 들여쓰기 잘못도 치명적 오류
  15. show()
  16.  
  17. from pylab import *
  18. i = arange(0.0,2*pi,0.1)
  19. for j in arange(0.0,2*pi,0.1):
  20.   x= 0.1*cos(i)+cos(j)
  21.   y= 0.1*sin(i)+sin(j)
  22.   plot(x,y)
  23. show()

2번 풀이

  1. # encoding:utf-8
  2. from pylab import *
  3. f = open("C:/logs.txt","r")
  4. lines = f.readlines()
  5. f.close()
  6. aList = map(lambda a:a.split(),lines)
  7.  
  8. del aList[0]
  9. nameList = map(lambda a:a[8],aList)
  10.  
  11. plot(map(lambda name:nameList.count(name),set(nameList)))
  12. show()


3번 풀이

  1. from pylab import *
  2.  
  3. t = arange(0.0, 5.0, 0.02)
  4. a = np.exp(-t)+np.exp(-4*t)
  5. plot(t, a,"r^")
  6.  
  7. b = np.exp(-t)*cos(sqrt(3)*t)+np.exp(-4*t)*sin(sqrt(3)*t)
  8. plot(t, b,"bo")
  9.  
  10. c = cos(2*t)+sin(2*t)
  11. plot(t, c,"b")
  12.  
  13. d = np.exp(-2*t)+t*np.exp(-2*t)
  14. plot(t, d,"g+")
  15.  
  16. title('About as simple as it gets, folks')
  17. grid(True)
  18. show()

4번 풀이

  1. from pylab import *
  2.  
  3. t = arange(0.0, 20.0, 0.02)
  4. s = 2*(sin(t)/1 - sin(2*t)/2 + sin(3*t)/3 - sin(4*t)/4+sin(5*t)/5)
  5. plot(t, s, linewidth=1.0)
  6.  
  7. title('About as simple as it gets, folks')
  8. grid(True)
  9. show()

샘플 01 1번 풀이

  1. from pylab import *
  2. t = arange(0.0, pi, 0.02)
  3. plot(t,sin(6*t),"g")
  4. plot(t,cos(6*t),"y")
  5. s = sin(6*t)+cos(6*t)
  6. plot(t, s, "r")
  7. k = sin(6*t)*cos(6*t)
  8. plot(t, k, "b")
  9. title('sin, cos add & sin, cos mult')
  10. grid(True)
  11. show()

2번 풀이

  1. from pylab import *
  2. a=[[0,0],[3,5],[3,8]]
  3. b=[[1,1],[3,6],[5,8]]
  4. print(map(lambda x,y:sqrt((x[1]-y[1])**2+(x[0]-y[0])**2),a,b))

3번

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. t = np.arange(0., 10, 0.1)
  5.  
  6. i = 1+1j
  7. print abs(i)
  8.  
  9. # log x and y axis
  10. plt.loglog(t, abs(1j*t/((1j*t*1j*t)+1j*t+1.0)))
  11. plt.grid(True)
  12.  
  13. plt.show()

4번

  1. from pylab import *
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. t = arange(0.0, 0.05, 0.0001)
  6. i = 100/(1+1j*4)
  7. print angle(i)
  8. It = imag(i*np.exp(1j*120*np.pi*t))
  9.  
  10. plot(t,It, "r")
  11. plot(t,imag(100*np.exp(1j*120*np.pi*t)),"b")
  12. show()
개인 도구