Input data for lsqnonlin
3 次查看(过去 30 天)
显示 更早的评论
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?!
0 个评论
采纳的回答
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.
0 个评论
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!