Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a new probabilistic matrix from two existing ones according to prespecified rules in MATLAB
    primarykey
    data
    text
    <p>I have a problem in my MATLAB code. Let me first give you some explanation about the issue. I have two matrices which represent probabilities of specific outcomes of events. The first one is called DemandProbabilityMatrix or in short DemandP. Entry (i,j) shows the probability that item i is demanded j many times. Similarly, we have a ReturnProbabilityMatrix, i.e. ReturnP. An element of type (i,j) stores the probability that item i is returned j many times. We want to compute the net demand probability out of these two matrices. For an example:</p> <blockquote> <p>DemandP=[ .4 .5 .1] ReturnP=[ .2 .3 .5]</p> </blockquote> <p>In this case we have 1 item and it can be demanded or returned either 1,2 or 3 times with the given probabilities. To be more specific That item will be demanded just for once with probability .4 .</p> <p>Then we need to compute the net demand. In this case, net demand can be -2,-1,0,1 or 2. For instance in order to get a net demand of -1 we can either have a demand of 1 and return of 2 or demand of 2 and return of 3. Thus we have </p> <blockquote> <p>NetDemandP(1,2)= DemandP(1,1)*ReturnP(1,2)+DemandP(1,2)*ReturnP(1,3).</p> </blockquote> <p>Thus the NetDemandP should look as:</p> <blockquote> <p>NetDemandP=[.20 .37 .28 .13 .02]</p> </blockquote> <p>I can do this with nested <code>for</code> loops but I'm trying to come up with a faster way. In case it helps I have the following <code>for</code> loops solutions where <code>I</code> denotes the number of rows in <code>ReturnP</code> and <code>DemandP</code>, <code>J+1</code> denotes the number of columns in those matrices.</p> <pre><code>NetDemandP=zeros(I,2*J+1); for i=1:I for j=1:J+1 for k=1:J+1 NetDemandP(i,j-k+J+1)=NetDemandP(i,j-k+J+1)+DemandP(i,j)*ReturnP(i,k); end end end </code></pre> <p>Thanks in advance</p>
    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.
 

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