matlab - Iteration of matrix-vector multiplication which stores specific index-positions -
matlab - Iteration of matrix-vector multiplication which stores specific index-positions -
i need solve min distance problem, see of work has beingness tried take at:
link: click here
i have four elements: two column vectors: alpha
of dim (px1)
, beta
of dim (qx1)
. in case p = q = 50
giving 2 column vectors of dim (50x1)
each. defined follows:
alpha = alpha = 0:0.05:2; beta = beta = 0:0.05:2;
and have two matrices: l1
, l2
.
l1
composed of 3 column-vectors of dimension (kx1)
each.
l2
composed of 3 column-vectors of dimension (mx1)
each.
in case, have equal size, meaning k = m = 1000
giving: l1
, l2
of dim (1000x3)
each. values of these matrices predefined.
they have, nevertheless, next structure:
l1(kx3) = [t1(kx1) t2(kx1) t3(kx1)]; l2(mx3) = [t1(mx1) t2(mx1) t3(mx1)];
the min. distance problem need solve given (mathematically) follows:
d = min( (x-(alpha_p*t1_k - beta_q*t1_m)).^2 + (y-(alpha_p*t2_k - beta_q*t2_m)).^2 + (z-(alpha_p*t3_k - beta_q*t3_m)).^2 )
the values x,y,z
3 fixed constants.
my problem
i need develop iteration can give me index positions combination of: alpha, beta, l1
, l2
fulfills min-distance problem above.
i hope formulation problem clear, have been careful index notations. if still not clear... step size for:
alpha
p = 1,...50
beta
q = 1,...50
for l1
; t1, t2, t3
k = 1,...,1000
for l2
; t1, t2, t3
m = 1,...,1000
and need find index of p
, index of q
, index of k
, index of m
gives me min. distance point x,y,z
.
thanks in advance help!
i don't know values wasn't able check code. using loops because obvious solution. pretty sure bsxfun
-brigarde ( ;-d ) find shorter/more effective solution.
alpha = 0:0.05:2; beta = 0:0.05:2; l1(kx3) = [t1(kx1) t2(kx1) t3(kx1)]; l2(mx3) = [t1(mx1) t2(mx1) t3(mx1)]; idx_smallest_d =[1,1,1,1]; smallest_d = min((x-(alpha(1)*t1(1) - beta(1)*t1(1))).^2 + (y-(alpha(1)*t2(1) - beta(1)*t2(1))).^2+... (z-(alpha(1)*t3(1) - beta(1)*t3(1))).^2); %the min. distance problem need solve given (mathematically) follows: p=1:1:50 q=1:1:50 k=1:1:1000 m=1:1:1000 d = min((x-(alpha(p)*t1(k) - beta(q)*t1(m))).^2 + (y-(alpha(p)*t2(k) - beta(q)*t2(m))).^2+... (z-(alpha(p)*t3(k) - beta(q)*t3(m))).^2); if d < smallest_d smallest_d=d; idx_smallest_d= [p,q,k,m]; end end end end end
what doing predefining smallest distance distance of first combination , checking each combination rather distance smaller previous shortest distance.
matlab min matrix-multiplication
Comments
Post a Comment