lsqnonlin return a result optimized nothing

I am trying to implement a math algorithm as my final project for my CV class, which can be found here: paper
Simplify the problem is: Minimize
With constraint:
And I wrote a function for the lsqnonlin() to obtain the result:
if true
function F = myfun(x, m, n, u, v, std_u, std_v)
% x = pm1 - pm13, x1,y1,z1,t1 - xn,yn,zn,tn
% m: # of picture
% n: # of point
% u: 2D points u direction i, j
% v: 2D points v direction i, j
F = 0;
for row = 1:m
for column = 1:n
Xi = x(1, 11+3*(n-1)+1);
Yi = x(1, 11+3*(n-1)+2);
Zi = x(1, 11+3*(n-1)+3);
error1 = u(row, column)*( x(row, 9) * Xi + x(row, 10) * Yi + x(row, 11) * Zi + 1 ) - ( x(row, 1) * Xi + x(row, 2) * Yi + x(row, 3) * Zi + x(row, 4) );
error2 = v(row, column)*( x(row, 9) * Xi + x(row, 10) * Yi + x(row, 11) * Zi + 1 ) - ( x(row, 5) * Xi + x(row, 6) * Yi + x(row, 7) * Zi + x(row, 8) );
F = F +(error1)*(error1) / std_u*std_u + (error2) * (error2) / std_v * std_v;
end
for column = 1:n
Xi = x(1, 11+3*(n-1)+1);
Yi = x(1, 11+3*(n-1)+2);
Zi = x(1, 11+3*(n-1)+3);
error3 = Xi * Xi + Yi * Yi + Zi * Zi;
F = F + abs(error3);
end
end
end
end
Where x is a matrix
X = [p1_11 - p1_33 , x1, y1, z1, t1, ...., xn, yn, zn, tn p2_11 - p2_33 , 0 ... 0 ... pm_11 - pm_33 , 0 ... 0] As i have to combine two parameter into one in order to use lsqnonlin(@F,X,[],[],options, 2, 40, u, v, val1, val2)
However, the function returned my initialed guess.
If you have any idea why this would happen please let me know

3 Kommentare

Torsten
Torsten am 5 Mai 2017
Bearbeitet: Torsten am 5 Mai 2017
As clearly written in the documentation of "lsqnonlin", the functions g_k must be returned separately, not their cumulated sum of absolute values.
So in your case, F must be a vector of size 2*(2*m*n+n), not a single scalar.
Furthermore, your quadratic constraint on the parameters to be fitted shows that "lsqnonlin" is not the correct tool to use, but "fmincon".
Best wishes
Torsten.
junqi yang
junqi yang am 5 Mai 2017
Thank you for the suggestion, I will give it a try.
junqi yang
junqi yang am 5 Mai 2017
Also, I used lsqnonlin because the author of that paper said they solve the equation by using levenberg-marquardt algorithm, and lsqnonlin is the only function can use levenberg-marquardt.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Tags

Gefragt:

am 5 Mai 2017

Kommentiert:

am 5 Mai 2017

Community Treasure Hunt

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

Start Hunting!

Translated by