MATLAB: How am I supposed to define each fi(x) functions of a nonlinear least-squares problem

lsqnonlinOptimization Toolbox

The NLS problem is to solve the function with a vector argument x.
f(x) = [ f1(x) f2(x) ….. fn(x) ]
x* could minimize f(x)
I'm trying to find the solution to of a GPS problem, with the least residual error.
fun3b = @(w) (w.*w-2.*xgps.*w+xgps.*xgps).^(1/2))-ygps; % this is wrong
sol_3 = lsqnonlin(fun3b, w0, [], []);
Here xgps is a 6×3 matrix with each row of the matrix as the coordinate, and ygps is a 6×1 with each row as the pseudorange.
In fact, fun3b should be @(w) (w.*w-2.*xgps[each row].*w+xgps[each row].*xgps[each row]).^(1/2))-ygps
[ f1(w)-ygps1 f2(w)-ygps2 …… fn(w)-ygpsn]
So is there any way to derive each row as the coefficient or at least allow us to define [ f1(x) f2(x) ….. fn(x) ] manually?

Best Answer

Assuming w is a 1x3 vector, the expression for each row that you have given
(w.*w-2.*xgps[each row].*w+xgps[each row].*xgps[eachrow]
results again in a 1x3 vector. So, it is not clear how you want this compared to ygps[eachrow] which is a scalar.
However, if I hazard a guess, you are trying to implement,
A=-2*xgps;
B=sum(xgps.^2,2) - ygps.^2;
fun3b=@(w) norm(w).^2 + A*w(:) + B;