# -*- coding: utf8 -*- import numpy as np import matplotlib.pyplot as plt a=10 def f(q): return a*np.e**(-0.5*q**2) def h(q): # return np.sqrt(q) plt.figure() q= np.arange(0, 2.01, 0.1)# plt.title(r'$y=f(q)$') # TeX plt.ylabel(r'$f(q)$') # y TeX plt.xlabel(r'$q$') # x TeX plt.grid(True) # plt.plot(q,f(q)) # plt.figure() plt.title(r'$y=h(q)$') # TeX plt.ylabel(r'$h(q)$') # y TeX plt.xlabel(r'$q$') # x TeX plt.grid(True) # plt.plot(q,h(q)) # plt.show() #
# -*- coding: utf8 -*- import pylab from mpl_toolkits.mplot3d import Axes3D import numpy as np xmax=1;ymax=1;N=20; h1=xmax/N;h2=ymax/N# def L1(x,y):# return 10*x*np.e**(-0.5*(x+y)**2)-np.sqrt(x) def L2(x,y):# return 10*y*np.e**(-0.5*(x+y)**2)-np.sqrt(y) def fi(a,b):# for w in range(0,len(a)+1): if a[w]==b: return w L= np.zeros([N+1,N+1])# for i in range(0,N+1): for j in range(0,N+1): L[i,j]=L1(i*h1,j*h2) A=[];e=[] rows, cols = L.shape for i in range(rows): e=[] for j in range(cols): e.append(L[i,j]) A.append(min(e)) a=max(A);ia=fi(A,a);xa=ia*h1# B=[];e=[] rows, cols = L.shape for j in range(cols): e=[] for i in range(rows): e.append(L[i,j]) B.append(max(e)) b=min(B);ib=fi(B,b);yb=ib*h2# p1=round(L1(xa,yb),3) print(" -"+str(p1)) p2=round(L2(xa,yb),3) print(" -"+str(p2)) def makeData_L1 ():# - z, - x,y x=[h1*i for i in np.arange(0,N+1)] y=[h2*i for i in np.arange(0,N+1)] x,y= np.meshgrid(x, y) z=[] for i in range(0,N+1): z.append(L1(x[i],y[i])) return x, y, z fig = pylab.figure() axes = Axes3D(fig) x, y, z = makeData_L1() axes.plot_surface(x, y, z) def makeData_L2 ():# - z - x,y x=[h1*i for i in np.arange(0,N+1)] y=[h2*i for i in np.arange(0,N+1)] x,y= np.meshgrid(x, y) z=[] for i in range(0,N+1): z.append(L2(x[i],y[i])) return x, y, z fig = pylab.figure() axes = Axes3D(fig) x, y, z = makeData_L2() axes.plot_surface(x, y, z) pylab.show()
# -*- coding: utf8 -*- import pylab import numpy as np xmax=1;ymax=1;N=20; h1=xmax/N;h2=ymax/N def L1(x,y): return 10*x*np.e**(-0.5*(x+y)**2)-np.sqrt(x) print(" -"+str(round(L1(xmax,ymax),3)))
# -*- coding: utf8 -*- import matplotlib.pyplot as plt import numpy as np xmax=1;ymax=1;N=20; h1=xmax/N;h2=ymax/N def L1(x,y): return 10*x*np.e**(-0.5*(x+y)**2)-np.sqrt(x) z=[L1(i*h1,i*h1)for i in np.arange(0,N+1)] x=[h1*i for i in np.arange(0,N+1)] xopt=x[z.index(max(z))] print(" -"+str(xopt)) print(" -"+str(round(max(z),3))) plt.title(' ') plt.grid(True) plt.plot(x,z) plt.show()
Source: https://habr.com/ru/post/335972/
All Articles