http://toranekosan.blogspot.com/2007_09_30_archive.html より
- またまたpythonで! http://toranekosan.blogspot.com/2007/10/python.html
- pythonでMatplotlib使おう! http://toranekosan.blogspot.com/2007/10/pythonmatplotlib.html
y = exp(-(x-0.5)^2)
import math def gaussfunc(x,a,b): return math.exp(-a*(x-b)*(x-b)) from pylab import * x = arange(-2.0, 2.0, 0.01) y=[] for e in x: y.append(gaussfunc(e,1.0,0.5)) plot(x, y, linewidth=1.0) show()
三次元関数 z = exp(-1.0*x^2-0.1*y^2)*(xy+x+y)
import math from pylab import * def gaussfunc(x,y,a,b): return exp(-a*(x)*(x)-b*(y)*(y)) dx, dy = 0.05, 0.05 x = arange(-3.0, 3.0, dx) y = arange(-3.0, 3.0, dy) X,Y = meshgrid(x, y) Z = gaussfunc(X, Y,1.0,0.5)*(Y*X+X+Y) im = imshow(Z,origin='lower' ,alpha=.9) cset = contour(Z, arange(-2.0,2.0,0.1), origin='lower' ) clabel(cset, inline=1, fmt='%1.1f', fontsize=10) hot() colorbar() show()
等高線いいねー
f(x,y) = exp(-X*X-Y*Y)*(2*X)*(4*Y*Y-2)
import math from pylab import * def gaussfunc(x,y,a,b): return exp(-a*(x)*(x)-b*(y)*(y)) dx, dy = 0.05, 0.05 x = arange(-3.0, 3.0, dx) y = arange(-3.0, 3.0, dy) X,Y = meshgrid(x, y) Z = gaussfunc(X, Y,1.0,0.5)*(2*X)*(4*Y*Y-2) im = imshow(Z,origin='lower' ,alpha=.9) colorbar(im) cset = contour(Z, arange(-2.0,2.0,0.2), origin='lower' ) clabel(cset, inline=1, fmt='%1.1f', fontsize=10) hot() show()