Input data for lsqnonlin

4 views (last 30 days)
Davide
Davide on 8 Apr 2015
Answered: Matt J on 8 Apr 2015
I'm solving a nonlinear least-squares problem using the lsqnonlin function. What I'm minimizing is the distance between some scattered 3D points(data) and a cylinder. The problem I encountered is on sending the 3D coordinates of the scattered points to the lsqnonlin function. And I need to have the coordinates of these points inside the lsqnonlin because I'm minimizing the distance between the calculated cylinder and the 3D points!
The problem is that, from what I understood, the lsqnonlin function accepts as input ONLY the first guessed value which, inside the lsqnonlin function, will be changed in order to optimize the function. So no space for other, constant input data?!
My optimization call looks like this where W0 is a vector of 3 elements defining the first guess for the cylinder orientation:
lsqnonlin(@Cylind_distance,W0,[-1,-1,-1],[1,1,1]);
The workaround I'm using at the moment is to create the 3D coordinates of the points as global variable, which can then be read inside the Cylind_distance function, but this is not really the best way because of several reasons... Any suggestion?!

Accepted Answer

Torsten
Torsten on 8 Apr 2015
lsqnonlin(@(x)Cylind_distance(x,arg1,arg2,...),W0,[-1,-1,-1],[1,1,1]);
where arg1, arg2,... are arguments to Cylind_distance supplied by the user.
Best wishes
Torsten.

More Answers (1)

Matt J
Matt J on 8 Apr 2015

Community Treasure Hunt

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

Start Hunting!