Trouble formulating minimization problem

I have the following minimization problem that I am trying solve in Matlab, but just not coming up with the right way to formulate it.
Given an image matrix V, I need to minimize the error function (not in Matlab format)
error = ∑ ( V(x,y) - f(x,y) )^2, summed over 1600 points (x,y)
where f(x,y) = P1 * x^2 + P2 * y^2 + P3 *x*y + P4*x + P5*y + P6
The goal is to determine the P1-P6 values. Any help would be greatly appreciated.
Keith

 採用された回答

Roger Stafford
Roger Stafford 2013 年 6 月 21 日

0 投票

I assume V is of double type.
[m,n] = size(V);
[x,y] = ndgrid(1:m,1:n);
x = x(:); y = y(:);
P = [x.^2,y.^2,x.*y,x,y,ones(m*n,1)]\V(:);
The elements of P will be your desired least square coefficients.

4 件のコメント

Keith
Keith 2013 年 6 月 21 日
Roger, That worked perfectly. Now if I can just understand what the heck you did, I'll be in good shape ( I had been going down the road of fminsearch with no luck). Thanks again.
Roger Stafford
Roger Stafford 2013 年 6 月 21 日
Read the documentation for 'mldivide' (backslash) in the section for over-determined linear equations: "If A is an m-by-n matrix with m ~= n and B is a column vector with m components, or a matrix with several such columns, then X = A\B is the solution in the least squares sense to the under- or overdetermined system of equations AX = B." In your case m is the number of points, (over 1600,) and n is six, so it is definitely over-determined.
http://www.mathworks.com/help/matlab/ref/mldivide.html
It is not necessary to use functions like 'fminsearch' because your expression is linear in the six unknown parameters.
Keith
Keith 2013 年 6 月 21 日
Thanks - that clears it up for me. Now if I can just solve the problem of having too many senior moments, ...
Roger Stafford
Roger Stafford 2013 年 6 月 21 日
When you solve that problem, please let me know. At age 87 I am having senior moments too.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2013 年 6 月 21 日
編集済み: Matt J 2013 年 6 月 21 日

0 投票

There is also this FEX file
which takes care to use QR factorizations, similar to polyfit.

1 件のコメント

Keith
Keith 2013 年 6 月 21 日
Matt - I'll definitely check this out as well. Thanks.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by