Iteration of matrix-vector multiplication which stores specific index-positions

一笑奈何 提交于 2019-12-12 06:27:08

问题


I need to solve a min distance problem, to see some of the work which has being tried take a look at:

link: click here

I have four elements: two column vectors: alpha of dim (px1) and beta of dim (qx1). In this case p = q = 50 giving two column vectors of dim (50x1) each. They are defined as follows:

alpha = alpha = 0:0.05:2;
beta = beta = 0:0.05:2;

and I have two matrices: L1 and L2.

L1 is composed of three column-vectors of dimension (kx1) each.

L2 is composed of three column-vectors of dimension (mx1) each.

In this case, they have equal size, meaning that k = m = 1000 giving: L1 and L2 of dim (1000x3) each. The values of these matrices are predefined.

They have, nevertheless, the following structure:

L1(kx3) = [t1(kx1) t2(kx1) t3(kx1)];
L2(mx3) = [t1(mx1) t2(mx1) t3(mx1)];

The min. distance problem I need to solve is given (mathematically) as 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 are three fixed constants.

My problem

I need to develop an iteration which can give me back the index positions from the combination of: alpha, beta, L1 and L2 which fulfills the min-distance problem from above.

I hope the formulation for the problem is clear, I have been very careful with the index notations. But if it is still not so clear... the step size for:

alpha is p = 1,...50

beta is q = 1,...50

for L1; t1, t2, t3 is k = 1,...,1000

for L2; t1, t2, t3 is m = 1,...,1000

And I need to find the index of p, index of q, index of k and index of m which gives me the min. distance to the point x,y,z.

Thanks in advance for your help!


回答1:


I don't know your values so i wasn't able to check my code. I am using loops because it is the most obvious solution. Pretty sure that someone from the bsxfun-brigarde ( ;-D ) will find a 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 I need to solve is given (mathematically) as follows:
for p=1:1:50
    for q=1:1:50
        for k=1:1:1000
            for 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 I am doing is predefining the smallest distance as the distance of the first combination and then checking for each combination rather the distance is smaller than the previous shortest distance.



来源:https://stackoverflow.com/questions/24363552/iteration-of-matrix-vector-multiplication-which-stores-specific-index-positions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!