3D nonlinear least squares fit in Matlab



Hi,
I am new to Matlab, and trying to solve the following
optimization problem:

It is a nonlinear least squares problem; my goal is to
derive the best-fit equations of seven straight lines (and
other standard output e.g. residuals etc.). I found
extensive documentation for Matlab functions, but all the
relevant ones (eg, fmincon) seem to be designed for the 2D
case. Please note that I need something that works for 3D
voxels, and to which I can feed my problem directly (ie, not
deriving the line equations separately, but together, since
I have some line intersection constraints as described below).

Problem formulation: let's call each straight line to be a
'rod' and the simple 3D structure to be the 'nest'. I have
seven set of (3D) data points. Each set represents a rod,
whose best-fit equation I need to derive. Each of these
seven rods has a common intersection (and at this
intersection both rods end), so a total of six
intersections. Thus, the seven rods together form my
cube-like 'nest'.

I have tried to formulate the problem as follows (please
view the link
http://sites.google.com/site/niazarifin/matlab-project-images
if the following cannot be read).

Let,
i denote my rod number, 1 <= i <= 7
m denote the total number of points in each of the 7
point-sets (which is the same for all 7),
p denote a point in the i-th point-set, 1 <= p <= m
(x0i, y0i, z0i) denote any point on rod i
Thus, (xpi, ypi, zpi) denote the p-th point on rod i

Then, equation of rodi is:
(x &#8211; x0i) / ai = (y &#8211; y0i) / bi =(z &#8211; z0i) / zi ... [1]

For least squares fit, the usual (unconstrained) equation,
fi(.), is:
f(x0i, y0i, z0i, ai, bi, ci | 1 <= i <= 7) =
&#8721; &#8721; { [ bi (z0i &#8211; zpi) &#8211; ci (y0i &#8211; ypi) ]2 +
1 <= i <= 7 1 <= p <= m [ ci (x0i &#8211; xpi) &#8211; ai (z0i &#8211; zpi)
]2 +
[ ai (y0i &#8211; ypi) &#8211; bi (x0i &#8211; xpi) ]2 }
... [2]
The distance cosine function for the i-th rod, hi(.), 1 <= i
<= 7, is:
ai2 + bi2 + ci2 = 1 ... [3]
The intersection constraint for rodi & rodi+1, gi(.), 1 <= i
<= 6, is:
ci [ai+1(y0i+1 &#8211; y0i) &#8211; bi+1(x0i+1 &#8211; x0i)] &#8211; ci+1 [ai(y0i+1
&#8211; y0i) &#8211; bi(x0i+1 &#8211; x0i)] &#8211; (ai+1bi &#8211; aibi+1) (z0i+1 &#8211; z0i) = 0
... [4]
([4] is obtained by using parametric equations of rodi &
rodi+1 and then equating the corresponding coefficients.)

Combining all these, and defining the Lagrangian &#955;i and &#956;i,
we get the Jacobian:
J = f(.) + h(.) + g(.)
= f(x0i, y0i, z0i, ai, bi, ci | 1 <= i <= 7)
+ &#8721; &#955;i (ai2 + bi2 + ci2 &#8211; 1)
1 <= i <= 7
+ &#8721; &#956;i (ci [ai+1(y0i+1 &#8211; y0i) &#8211; bi+1(x0i+1 &#8211; x0i)] &#8211; ci+1
[ai(y0i+1 &#8211; y0i) &#8211; bi(x0i+1 &#8211; x0i)] &#8211; (ai+1bi &#8211; aibi+1)
(z0i+1 &#8211; z0i))
1 <= i <= 6

Since I never used any optimizer before, I'd truly
appreciate if you can help on (for this 3D case):

1.which Matlab function to use for the problem
2.what form of output I should expect
3.I know there is extensive documentation for each Matlab
function, yet I'd welcome the formulation of this problem to
directly feed to the Matlab function chosen in 1.

Thanks a lot for your valuable time!
.



Relevant Pages

  • Re: ML matrices multiplication accuracy
    ... I wrote a simple matlab function to do the matrices ... I found that the result is not equal to the built-in matlab ... give the same answer as would be expected, but this differs by one bit ... "These instructions combine multiply ...
    (comp.soft-sys.matlab)
  • Re: compile C S-Function which uses MEX calls with RTW
    ... you are right, RTW does not support ... MATLAB). ... I suspect the Embedded Matlab block (embedding Matlab calls ... I agree with the exception of 3): the Embedded MATLAB function ...
    (comp.soft-sys.matlab)
  • Re: ML matrices multiplication accuracy
    ... I wrote a simple matlab function to do the matrices ... Does matlab uses some sort of inaccurate algorithm to ... give the same answer as would be expected, but this differs by one ... "These instructions combine ...
    (comp.soft-sys.matlab)
  • Re: Problem with Fortran main program calling Matlab engine function
    ... on which directory to store the matlab function for fortran calling ... mexCallMATLAB function in an engine application? ...
    (comp.soft-sys.matlab)
  • Re: ML matrices multiplication accuracy
    ... I wrote a simple matlab function to do the matrices multiplication: ... I found that the result is not equal to the built-in matlab operator ... floating point arithmetic violates the associative law of addition: ... floating point computations and are not unique to matlab's system. ...
    (comp.soft-sys.matlab)

Loading