fitting a linear surface with numpy least squares

余生长醉 提交于 2019-12-01 09:27:44

I think you're on the right track. You could still try following the example of the scipy.linalg documentation, in particular the Solving least-squares...` section

A = np.column_stack((np.ones(x.size), x, y))
c, resid,rank,sigma = np.linalg.lstsq(A,zi)

(we added a column of 1 for the constant).

The constants a, b, and c are the unknowns you need to solve for.

If you substitute your N (x, y, z) points into the equation, you'll have N equations for 3 unknowns. You can write that as a matrix:

[x1 y1 1]{ a }   { z1 }
[x2 y2 1]{ b }   { z2 }
[x3 y3 1]{ c } = { z3 }
    ...
[xn yn 1]        { zn }

Or

Ac = z

where A is an Nx3 matrix, c is a 3x1 vector and z is a 3xN vector.

If you premultiply both sides by the transpose of A, you'll have an equation with a 3x3 matrix that you can solve for the coefficients you want.

Use LU decomposition and forward-back substitution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!