I need to make a monte carlo simulation for a problem of weight.
The weight of one shipping pallete is 15 boxes, and each box contains 260 X pieces and 140 Y pieces. The weights of x are distributed normally with mean of 1.2 and 0.18 standard deviation. The weights of y are distributed uniformly between 1.1 and 1.5. The max weight of each pallete is 7430.
I need to make a monte carlo simulation to find the convergence for the chance of the pallete being max weight or overweight. I also need to find the mean, standard deviation.
I have written code for this sampled from another simulation I wrote.
N = 100 ;Box = zeros(N,1);Relativefreq=zeros(N,1);count=0 ;for i=1:100 X =(260*(1.2+0.18*randn(1,10))) %weight of X already multiplied by number of parts
Y =(140*(1.1+(1.5-1.1)*rand(10,1)))' %weight of Y multiplied by number of parts
Pallete(i)=15*X+15*Y; %should calculate weight of each box, multiplied by 15 per pallete. Keeps getting error that it is not the same number of elements.
if Pallete(i)>=7430; %test to see if the box is overweight
count = count + 1 ;endRelativefreq(i) = count/i ; %should be relative frequency of the box being overweight
endfigure[x,c]=hist(Box,ceil(2*length(i))^1/3); %makes histogram data with the number of bins according to the Reiss rule.
h=gca;set(h,'XTick',c);x/sum(x);bar(c,x/sum(x)); %should print the histogram for the relative frequency of the weights.
xlabel('Weight Of Palletes'), ylabel('Relative Frequency');figure;plot(1:N,Relativefreq),grid %should make a convergence diagram to find the probability it is at max or overweight.
axis tight;xlabel('Number of trials'),ylabel('Prob that its overweight');mean=mean(Pallete(i)) %should calc mean weight of each pallete, dosent work.
s=std(Pallete(i)) %should calc the standard deviation of each pallete weight
Best Answer