1.2.3绘制曲线、图示
对于由指数函数和正弦函数相乘形成的新函数:
\[y = e ^{ax}sinbx\] 当a = -0.5,b = 2时,画出函数曲线,在曲线上标记极大值。a = -0.5b = 2x = arange(0, 10, 0.01)y = exp(a * x)*sin(b*x) #显示曲线plot(x,y,label = "$y=e^{ax}sin^{bx}$ \n$a=-0.5,b=2$", color = "red")legend() #显示图示 #求极值ym = []xm = []ym.append(y.max())xm.append(x[y.argmax()]) #绘制极值和极值杆线stem(xm,ym, "--")txt = "({0},{1})".format(str(xm[0]),str(ym[0]))text(xm[0], ym[0], txt) #显示网格grid()title(u"函数曲线")xlabel(u"横坐标")ylabel(u"纵坐标")
结果如图
1.2.4绘制曲线组和极值函数
绘制当 b = 0.5 , a = -0.6到0的7个值,间隔为0.1,画出函数曲线族,画极大值杆线,画出极大值的分布曲线。
对于函数任意连续函数,其导数 = 0处为其极值。\[y = e ^{ax}sinbx\]的导数为:\[y = ae^{ax}sinbx + be^{ax}cosbx\] 令\[y^、 = 0\] 则得\[tanbx_m + \frac ba = 0\]
即
\[x_m = \frac {1}{b}(n\pi - arctan\frac ba), n = 0,1,2,...\]
对于第一个极值,n取0。
x = arange(0,20,0.2)b = 0.5a = arange(-0.6,0,0.1)A,Y = meshgrid(a,x)Y = exp(A*X)*sin(b*X)plot(x,Y)grid()legend(a) #绘制极值杆线,不如matlab方便ym = []offset = []for col in tY: ym.append(col.max()) offset.append(col.argmax()) xm = []for i in offset: xm.append(x[i])stem(xm,ym,"--") #绘制极值函数图形a = arange(-1,-0.001,0.001)xm = -arctan(b/a)/bym = exp(a * xm) * sin(b * xm)plot(xm, ym,"--") #~~title(u"函数曲线族" + "$y=e^{ax}sinbx$")xlabel("$\itx$")ylabel("$\ity$")