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.
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 Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by