200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python二元函数图像绘制_用python绘制二元函数

python二元函数图像绘制_用python绘制二元函数

时间:2023-01-16 09:32:21

相关推荐

python二元函数图像绘制_用python绘制二元函数

我得画一个双变量函数来检验模型的退化性。我的代码如下所示:from numpy import exp,arange

from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show

import math

# the function that I'm going to plot

def z_func(x1,x2):

L = exp(-(1-x1)**2 - 100((x2-x1**2)**2))

return L

x1 = arange(-5.0,5.0,0.1)

x2 = arange(-5.0,5.0,0.1)

X1,X2 = meshgrid(x1, x2) # grid of point

Z = z_func(X1, X2) # evaluation of the function on the grid

im = imshow(Z,cmap=cm.RdBu) # drawing the function

# adding the Contour lines with labels

cset = contour(Z,arange(-1,1.5,0.2),linewidths=2,cmap=cm.Set2)

clabel(cset,inline=True,fmt='%1.1f',fontsize=10)

colorbar(im) # adding the colobar on the right

# latex fashion title

title('$z=exp(-(1-x1)^2 - 100(x2-x1^2)^2)$')

show()

我得到了以下错误:

^{pr2}$

我想我该如何定义我的函数,如何修正这个错误并绘制函数图是有问题的?在

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。