Artificial intelligent assistant

3D surface fitting I am attempting to find the mathematical representation of a surface given a set of (x,y,z) data points. I recently tried using the method of least-squares which worked well for most of my situations. However, in some instances I am getting the result that in: $(A^{T}*A)^{-1}*A^{T}*b$ the term $(A^{T}*A)$ is ill-conditioned or nearly singular. My formulation for A is in the format $1+x+y+xy+x^{2}+y^{2}$. Is there a way to prevent these instances from happening? I've heard of applying a svd to least-squares as an alternative, but was unable to find exactly how. Any help would be greatly appreciated.

Try using Moore-Penrose pseudoinverse $A^+\\!$, it coincides with $(A^TA)^{-1}A^T$ when the inverse exists but is defined for any $A$. When $A^TA$ is singular there are multiple least square fits, and pseudoinverse will give you the one with the smallest Euclidean norm. Stable numerical methods for computing $A^+$ are based on singular value decomposition or the QR method, but if you are using MATLAB or something similar there should be a direct command for it.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a416ebcefc4b7cf977a433b522f8eaaf