3D nonlinear least squares fit in Matlab
- From: "S M Niaz Arifin" <niazarifin@xxxxxxxxx>
- Date: Thu, 14 Aug 2008 15:24:03 +0000 (UTC)
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 – x0i) / ai = (y – y0i) / bi =(z – z0i) / zi ... [1]
For least squares fit, the usual (unconstrained) equation,
fi(.), is:
f(x0i, y0i, z0i, ai, bi, ci | 1 <= i <= 7) =
∑ ∑ { [ bi (z0i – zpi) – ci (y0i – ypi) ]2 +
1 <= i <= 7 1 <= p <= m [ ci (x0i – xpi) – ai (z0i – zpi)
]2 +
[ ai (y0i – ypi) – bi (x0i – 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 – y0i) – bi+1(x0i+1 – x0i)] – ci+1 [ai(y0i+1
– y0i) – bi(x0i+1 – x0i)] – (ai+1bi – aibi+1) (z0i+1 – 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 λi and μi,
we get the Jacobian:
J = f(.) + h(.) + g(.)
= f(x0i, y0i, z0i, ai, bi, ci | 1 <= i <= 7)
+ ∑ λi (ai2 + bi2 + ci2 – 1)
1 <= i <= 7
+ ∑ μi (ci [ai+1(y0i+1 – y0i) – bi+1(x0i+1 – x0i)] – ci+1
[ai(y0i+1 – y0i) – bi(x0i+1 – x0i)] – (ai+1bi – aibi+1)
(z0i+1 – 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!
.
- Prev by Date: Re: Locking assertion failure.
- Next by Date: Re: Creating duplicate rows using weighting vector
- Previous by thread: Re: Locking assertion failure.
- Next by thread: guidata, appdata or userdata for large datasets?
- Index(es):
Relevant Pages
|
Loading