MATLAB: Fitting a surface over a mxn matrix

poly11surface fit

Hi,
I have a function u(x,y) which I wish to fit using the 'poly11' option within the 'fit' funtion The problem is that x, y, and u are all m x n matrices with m not equal to n. I can fit the data using the sftool but I would like to do it in a programmatic way. Any help will be greatly appreciated.
Thanks, Andy

Best Answer

Poking around a bit, poly11 appears to fit a polynomial of the form a*x + b*y + c. I could be wrong on that, perhaps there is an x*y term as well, but my interpretation of the documentation is that there is no x*y term.
If your equation to fit is indeed of the form a * x + b * y + c, then it can be rewritten as being of the form
U = [x y 1] * [a;b;c]
where [a;b;c] are unknowns to determine.
This can then be rewritten as a simple mldivide ('\') operation:
U(:) \ [x(:) y(:) ones(numel(x),1)]
or some close relative thereof (I keep forgetting the order of the components)
Related Question