# Can I plug functions created with lambda x on a list? (python)

I need to build a polynomial function like a_0 + a_1x + a_2x^2 ... I am trying to do the whole interpolation process. I have this:

``````def Create_F(Numero, Array):
Y = lambda x: x
Lista = list(Array)
F_x = []
for i in range(Numero):
G_x = lambda x: eval(Lista[i]*Y^i)
F_x.append(G_x)
return F_x
``````

And if I use this, I do not get nothing that help:

``````Number = 2
ma = np.array([[1, 1],
[1, 2]])
ly = np.array([8, -3])

idk = Create_F(Number, ly)
print(idk)
``````

I don't know how to evaluate, for example 1. If I can do this in a better way it would be very helpful, the complete code is:

``````import numpy as np

def Matrix_F(Num, Lx):
Vec = np.zeros((Num, Num), dtype = float)
Vec.T = Lx
ex = 0
for i in range(Num):
for j in range(Num):
Vec[j][i]=Lx[j]**ex
ex += 1
return Vec

def Cramer_F(Ma, Ly):
Lc, Det = np.array(Ly), np.linalg.det(Ma)
col = len(Lc)
Values = np.zeros(col)
for i in range(col):
org = Ma.copy()
org.T[i]=Lc
Di=np.linalg.det(org)
Values[i] = Di/Det
error = np.linalg.norm(np.dot(Ma, Values)-Lc)
return Values, error

def Create_F(Numero, Array):
Y = lambda x: x
Lista = list(Array)
F_x = []
for i in range(Numero):
G_x = lambda x: eval(Lista[i]*Y^i)
F_x.append(G_x)
return F_x

val = int(input('Ingrese la cantidad de valores de X y Y que posee: '))
x_val = []
y_val = []

print('Ingrese %s valores de cada variable:' %(val))

n = 1
for i in range(val):
x = float(input('%s° Valor de x: '%(n)))
y = float(input('%s° Valor de y: '%(n)))
x_val.append(x)
y_val.append(y)
n += 1

#Matriz del sistema:
As = Matrix_F(val, x_val)

#Valores de "a_n" y error
a_val, er = Cramer_F(As, y_val)

n=0
print()
for i in a_val:
print('a_%s = %.6f' %(n, i))
n += 1
``````