import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt import time C=2000 # e=0.3# VCzad=1400# w4=4000# def f(a):# return C*np.log(a/(1+e*a)) def VC2(w3,w2):# return VCzad-f(w4/w3)-f(w3/w2) def w1(w3,w2):# return (w2/(np.e**(VC2(w3,w2)/C)))-e*w2 start = time.time()# def fun1(x,y):# (x=w3, y=w2) return 4000/(-0.3*y+y*np.e**(np.log(x/(0.3*x+y))+np.log(4000/(1200+x))-0.7))
#!/usr/bin/env python #coding=utf8 import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def fun1(x,y):# return 4000/(-0.3*y+y*np.e**(np.log(x/(0.3*x+y))+np.log(4000/(1200+x))-0.7)) x= np.linspace(500,5000,10000) y = np.linspace(500,5000,10000) z=fun1(x,y) fig = plt.figure(' ') ax= Axes3D(fig) ax.plot(x,y,z,linewidth=1) plt.show()
def fun2(x): return fun1(*x)
import numpy as np from scipy.optimize import minimize import time start = time.time() def fun1(x,y): return 4000/(-0.3*y+y*np.e**(np.log(x/(0.3*x+y))+np.log(4000/(1200+x))-0.7)) def fun2(x): return fun1(*x) x0 =[3000,2000] # res = minimize(fun2, x0, method='SLSQP', bounds=None) stop = time.time() print (" :",round(stop-start,3)) print(res)
import numpy as np from scipy.optimize import minimize import time start = time.time() def fun1(x,y): return 4000/(-0.3*y+y*np.e**(np.log(x/(0.3*x+y))+np.log(4000/(1200+x))-0.7)) def fun2(x): return fun1(*x) x0 =[3000,2000] # res = minimize(fun2, x0)) stop = time.time() print (" :",round(stop-start,3)) print(res)
import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt import time C=2000 # e=0.3# VCzad=1400# w4=4000# def f(a):# return C*np.log(a/(1+e*a)) def VC2(w3,w2):# return VCzad-f(w4/w3)-f(w3/w2) def w1(w3,w2):# return (w2/(np.e**(VC2(w3,w2)/C)))-e*w2 start = time.time()# def fun1(x,y):# (x=w3, y=w2) return 4000/(-0.3*y+y*np.e**(np.log(x/(0.3*x+y))+np.log(4000/(1200+x))-0.7)) def fun2(x): return fun1(*x) x0 =[3000,2000] res = minimize(fun2, x0) stop = time.time() print (" :",round(stop-start,3)) print (" :",round(res['fun'],3)) w2=round(res['x'][1],3) w3=round(res['x'][0],3) w1=round(w1(w3,w2),3) v1=round(f(w2/w1),3) v2=round(f(w2/w1)+f(w3/w2),3) v3=round(f(w2/w1)+f(w3/w2)+f(w4/w3),3) print(" -:%s;%s;%s;%s "%(w4,w3,w2,w1)) print(" -:%s;%s;%s;%s "%(0,v1,v2,v3)) VES=[w4,w3,w2,w1] VC=[0,v1,v2,v3] plt.title(" \n ") plt.plot(VES,VC,'o') plt.plot(VES,VC,'r') plt.xlabel(" ") plt.ylabel(" ") plt.grid(True) plt.show()
import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt import time C=2000 # e=0.4# w4zad=4000# w1zad=200# def f(a): return np.log(a/(1+e*a)) def Vc1(w3): return C*f(w4zad/w3) def Vc2(w3,w2): return C*f(w3/w2) def Vc3(w2): return C*f(w2/w1zad) start = time.time() def fun1(x, y): return -(C*np.log((w4zad/y)/(1+e*(w4zad/y)))+ C*np.log((y/x)/(1+e*(y/x)))+C* np.log((x/w1zad)/(1+e*(x/w1zad))))
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D C=2000 # e=0.4# w4zad=4000# w1zad=200# def fun1(x, y): return -(C*np.log((w4zad/y)/(1+e*(w4zad/y)))+ C*np.log((y/x)/(1+e*(y/x)))+C* np.log((x/w1zad)/(1+e*(x/w1zad)))) x= np.linspace(500,5000,10000) y = np.linspace(500,5000,10000) z=fun1(x,y) fig = plt.figure(' ') ax= Axes3D(fig) ax.plot(x,y,z,linewidth=1) plt.show()
import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt import time C=2000 # e=0.4# w4zad=4000# w1zad=200# def f(a): return np.log(a/(1+e*a)) def Vc1(w3): return C*f(w4zad/w3) def Vc2(w3,w2): return C*f(w3/w2) def Vc3(w2): return C*f(w2/w1zad) start = time.time() def fun1(x, y): return -(C*np.log((w4zad/y)/(1+e*(w4zad/y)))+ C*np.log((y/x)/(1+e*(y/x)))+C* np.log((x/w1zad)/(1+e*(x/w1zad)))) def fun2(x): return fun1(*x) x0 = (1000,2000) res = minimize(fun2, x0) stop = time.time() print (" :",round(stop-start,3)) print (" :",round(res['fun'],3)) w2=round(res['x'][0],3) w3=round(res['x'][1],3) v1=round(Vc1(w3),3) v2=round(Vc1(w3)+Vc2(w3,w2),3) v3=round(Vc1(w3)+Vc2(w3,w2)+Vc3(w2),2) print(" -:%s;%s;%s;%s "%(w4zad,w3,w2,w1zad)) print(" -:%s;%s;%s;%s "%(0,v1,v2,v3)) VES=[w4zad,w3,w2,w1zad] VC=[0,v1,v2,v3] plt.title(" \n ") plt.plot(VES,VC,'o') plt.plot(VES,VC,'r') plt.xlabel(" ") plt.ylabel(" ") plt.grid(True) plt.show()
Source: https://habr.com/ru/post/344280/
All Articles