Fitting a surface over a mxn matrix

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

 Accepted 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)

2 Comments

In fact poly11 fits a function of the form f(x,y) = a + b*x + c*y. By using your method wouldn't I get the coefficients a, b, and c which are each m x n matrices since x and y are both m x n?
Notice the (:) that I used: that turns the arrays in to column vectors. U(:) will be an n*m x 1 column vector, the part to the right will be an n*m x 3 array, and the result of fitting will be a 3 x 1 array (provided I got the terms in the right order: see mldivide for examples.)

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!