Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First I should note that the R code might be misleading to some Matlab users because <code>A*B</code> in R is equivalent to <code>A.*B</code> in Matlab (element-wise multiplication). I used symbolic variables in my calculations so that the operations that take place are clearer. </p> <pre><code>syms a11 a12 a21 a22 b11 b12 b21 b22 syms a13 a31 a23 a32 a33 syms b13 b31 b23 b32 b33 </code></pre> <p>First consider the easiest case we have only 1 vector A and 1 vector B : </p> <pre><code>A1 = [a11;a21] ; B1 = [b11;b21] ; </code></pre> <p>The result you want is </p> <pre><code>1 - prod(1-A1.*B1) = 1 - (a11*b11 - 1)*(a12*b12 - 1) </code></pre> <p>Now assume we have 3 vectors A and 2 vectors B stacked one next to the other in columns:</p> <pre><code>A3 = [a11 a12 a13;a21 a22 a23; a31 a32 a33]; B2 = [b11 b12 ;b21 b22 ; b31 b32]; </code></pre> <p>In order to get the indices of all the possible combinations of columns vectors of A3 paired with all the possible combinations of column vectors of B2 you can do the following:</p> <pre><code>[indA indB] = meshgrid(1:3,1:2); </code></pre> <p>Now since for pairwise product of two vectors a,b it holds that <code>a.*b = b.*a</code> we can just keep the unique pairs of indices. You can do that as follows:</p> <pre><code>indA = triu(indA); indB = triu(indB); indA = reshape(indA(indA&gt;0),[],1); indB = reshape(indB(indB&gt;0),[],1); </code></pre> <p>Now the result that you want could be calculated:</p> <pre><code>result = 1 - prod(1-A3(:,indA).*B2(:,indB)) </code></pre> <p>Just for better readability:</p> <pre><code>pretty(result.') = +- -+ | (a11 b11 - 1) (a21 b21 - 1) (a31 b31 - 1) + 1 | | | | (a12 b11 - 1) (a22 b21 - 1) (a32 b31 - 1) + 1 | | | | (a12 b12 - 1) (a22 b22 - 1) (a32 b32 - 1) + 1 | | | | (a13 b11 - 1) (a23 b21 - 1) (a33 b31 - 1) + 1 | | | | (a13 b12 - 1) (a23 b22 - 1) (a33 b32 - 1) + 1 | +- -+ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload