def invoke(self): functions = [ Function("y = sin(x)", lambda x: np.sin(x)), Function("y = sin(x) + cos(x)", lambda x: np.sin(x) + np.cos(x)), Function("y = 3x^3 - 2x^2 + 2", lambda x: 3 * np.power(x, 3) - 2 * np.power(x, 2) + 2) ] log( "> {} Welcome to interpolation world {}\n".format( self.DASH, self.DASH), COLOR.HEADER) log("> Please choose your function:\n", COLOR.OKGREEN) for i, func in enumerate(functions): print("> {}. {}".format(i, func.to_str())) log("> Enter your option: ", COLOR.OKGREEN) opt_func = int(input()) chosen_func = functions[opt_func] log(self.DASH * 3 + '\n', COLOR.HEADER) log("> Please choose the way to generate interpolation points: \n", COLOR.OKGREEN) log("> 0. Manual\n") log("> 1. Auto generate (random points)\n") log("> Enter your option: ", COLOR.OKGREEN) opt_gene = int(input()) x = self.generate(opt_gene) y_org = chosen_func.f(x) lagrange = Lagrange(x, y_org) y_lag = [lagrange.f(xi) for xi in x] self.draw(x, y_org, y_lag, chosen_func, lagrange)
def lagrange_results(): n = request.form.get("n") x = request.form.get("x") y = request.form.get("y") if n == '' or x == '' or y == '': return "<h1 style='text-align: center;'>Check Values Entered</h1>" try: A = int(n) except: return "<h1 style='text-align: center;'>Check n value entered</h1>" try: values_x = list(map(float, x.split())) except: return "<h1 style='text-align: center;'>Check x vector entered</h1>" try: values_y = list(map(float, y.split())) except: return "<h1 style='text-align: center;'>Check y vector entered</h1>" try: A, b, a = Lagrange(n, x, y) except: return "<h1 style='text-align: center;'>Check values entered</h1>" return render_template("lagrange.html", A=A, b=b, a=a)
def generateEulerLagrange(self): self.createVariables() self.derivModel() K, P = self.getEnergies() L = Lagrange(self.nodes) D, H, G = L.euler_lagrange(K, P, self.q, self.dq, self.ddq) # H is actually H*(dq**2) try: answer = input( "Do you want to simplify the lagrangian?(Might take some time) \n\n[y/n]:" ) if (answer.lower() == "y"): D, H, G = self.simplifyLagrangian(D, H, G) else: print("\n\n-- Matrix D:\n", D, "\n\nMatrix H:\n", H, "\n\nMatrix G:\n", G) except: print("Don't know what you did but...") print("\n\n-- Matrix D:\n", D, "\n\nMatrix H:\n", H, "\n\nMatrix G:\n", G) J = self.jacobianGeneralizedPositionMatrix() return D, H, G, J, K, P
def calculate(self): textbox.insert('1.0', "Starting.. \n") global A, B, C, D A = int(firstCoeff.get("1.0", END)) B = int(secondCoeff.get("1.0", END)) C = int(thirdCoeff.get("1.0", END)) D = int(fourthCoeff.get("1.0", END)) textbox.insert(END, 'Составим функцию Лагранжа: \n') textbox.insert( END, "F(x,y,z,lambda)= x^2 + y^2 + z^2 - lambda*(" + str(A) + "x " + sign(B) + str(B) + "y " + sign(C) + str(C) + "z " + sign(D) + str(D) + ")\n") textbox.insert(END, "dF/dx = 2x - lambda*" + str(A) + " = 0\n") textbox.insert(END, "dF/dy = 2y - lambda*" + str(B) + " = 0\n") textbox.insert(END, "dF/dz = 2z - lambda*" + str(C) + " = 0\n") textbox.insert( END, "dF/dlambda = " + sign2(A) + str(A) + "x " + sign2(B) + str(B) + "y " + sign2(C) + str(C) + "z " + sign2(D) + str(D) + " = 0 \n") results = Lagrange.solve(A, B, C, D) rounded_results = [] for result in results: result = round(result, 3) rounded_results.append(result) X = rounded_results[0] Y = rounded_results[1] Z = rounded_results[2] Lambda = rounded_results[3] textbox.insert(END, str(rounded_results) + "\n") textbox.insert(END, "Lambda = " + str(Lambda) + "\n") textbox.insert(END, "X = " + str(X) + "\n") textbox.insert(END, "Y = " + str(Y) + "\n") textbox.insert(END, "Z = " + str(Z) + "\n") F = X * X + Y * Y + Z * Z textbox.insert( END, "Значение исходной функции f = x^2 + y^2 + z^2 равно: " + str(F) + "\n") drawPlot()
from numpy import loadtxt import matplotlib.pyplot as plt from lagrange import Lagrange from scipy import linspace from scipy.interpolate import interp1d a = loadtxt("datafile.dat") xinterp = linspace(min(a[:,0]),max(a[:,0]),500) Lg = Lagrange() punt = Lg.funcion(a[:,0], a[:,1], xinterp) aux = punt[0] cont = 0 for i in range(len(punt)): if aux < punt[i]: aux = punt[i] cont = i Er = aux Erx = xinterp[cont] med = Er/2 aux1 = 0 aux2 = 0 gamma = 0 for i in range(len(punt)//2): if punt[cont-i] < med: aux1 = cont-i break for i in range(len(punt)//2): if punt[cont+i] < med:
if aoidict.has_key(stimulus): aoidict[stimulus].append(aoi) else: aoidict[stimulus] = [aoi] del aoi # print aoidict for key in aoidict: print key print "number of AOIs: ", len(aoidict[key]) for aoi in aoidict[key]: aoi.dump() lagrange = Lagrange(int(width), int(height)) for file in files: scanpath = Scanpath() scanpath.parseFile(file, width, height, herz) base = os.path.basename(file) print "Processing: ", file, "[", base, "]" subj, ext = os.path.splitext(base.split('_')[0]) # extract stimulus name imagebase, ext = os.path.splitext(base.split('_')[1]) if imagebase == 'Vertical':
#!/usr/bin/python2 from lagrange import Lagrange file = raw_input('File: ') shares = open(file, 'r').read().split() xs = [int(i.split('-')[0]) for i in shares] ys = [int(i.split('-')[1]) for i in shares] print(Lagrange(xs, ys).interpolate())