从x,y,z数据生成曲面方程

时间:2015-08-04 21:36:19

标签: python math numpy spline surface

为x,y和z已知的曲面生成方程的最有效方法是什么?似乎有很多方法可以通过样条从几个数据点插入样条曲线,但是,我拥有代表光滑曲面的所有数据点,并且仍然没有一个代表整个曲面的方程。每个样条都相当简单,因为它上升和下降一次。

我已经在Brandon Stafford's blog的最小二乘示例中生成了一个等式,但得到的等式并不代表更复杂的形式。

我意识到缺少交叉术语。如何将每个交叉项(xy,xy ^ 2,x ^ 2y,x ^ 3y,x ^ 3y ^ 2,y ^ 3x,y ^ 3x ^ 2)添加到脚本中?一旦我有交叉术语,我需要为它们添加度数吗?

# Set up the canonnical least squares form
Ax = np.vander(X,degree)
Ay = np.vander(Y,degree)
A = np.hstack((Ax,Ay))

# Solve for the least squares estimate of current
(coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(A, Z)

# Extract coefficients and create polynomials in x and y
xcoeffs = coeffs[0:degree]
ycoeffs = coeffs[degree:2 * degree]

fx = np.poly1d(xcoeffs)
fy = np.poly1d(ycoeffs)

print fx
print fy

0 个答案:

没有答案