I am attempting to fit data of a bi-variate polynomial using normal polynomials.I have started with the example on bivariate data fitting: Fitting polynomials to data
Issue is these are not orthogonal so coeffs change as degree changes. My plan was to use legendre polynomials (build X and Y polynomials and then take cross product similarly to how I build A list below) but I am stuck on how to then fit the data.
def least_sqr(n,degree,x,y,DEL):
#n==length of list x#
A = []
for i in range(n):
A.append([])
for xd in range(degree+1):
for yd in range(degree+1-xd):
A[i].append((x[i]**xd)*(y[i]**yd)) #f_j(x_i)
q,_,_,_ = linalg.lstsq(A,DEL)
return q
def MAIN():
x,y,delx,dely,n = data_parse(file1, file2, file3, file4);
degree=3
q=least_sqr(n,degree,x,y,delx)
r=least_sqr(n,degree,x,y,dely)