Input data for lsqnonlin

조회 수: 3 (최근 30일)
Davide
Davide 2015년 4월 8일
답변: Matt J 2015년 4월 8일
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?!

채택된 답변

Torsten
Torsten 2015년 4월 8일
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.

추가 답변 (1개)

Matt J
Matt J 2015년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by