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

 采纳的回答

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 个评论

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.
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.
Thanks - that clears it up for me. Now if I can just solve the problem of having too many senior moments, ...
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
There is also this FEX file
which takes care to use QR factorizations, similar to polyfit.

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by