Store value into matrix, and then perform calculation upon each element

7 ビュー (過去 30 日間)
Ying 2012 年 2 月 6 日
編集済み: Matthew Crema 2013 年 10 月 8 日
Hi, I have a question about performing calculation on each matrix elements.
My code is here:
syms m a x u;
for i=1:10^2
X = betainv(u,2,3); % beta distributed random fraction of defective parts
Y = logninv(u,5,3); % lognormal distributed demand amount
Q = 100;
Revenue=min(Y,(1-X)*Q)*53; %the total revenue
Salvage=3*max(Q*(1-X)-Y,0)+X*Q; %all the unsolde parts are salvaged, defective parts included
Basically, I generate a series of uniformly distributed random numbers. And then I use these numbers to genearate beta and lognormal distributed ones, and I would like to store them into matrix X and Y. Then I want to perform the profit calculation (revenue-cost+salvage cost etc.) for each of the values in X and Y. I just don't know how to do that.
I tried to put things as X(i) and Y(i) (to store value into matrix), but MLATLAB finds an error in that step.
I just started learning Monte Carlo simulation using MATLAB. Hope somebody can help me out here.
Thanks a lot! Ying


Ondrej 2012 年 2 月 6 日
I guess you want to do
X(i) = betainv(u(i),2,3);
Y(i) = logninv(u(i),5,3);
you either missed the u(i) index, or you want to store growin u, in that case X(:,i), Y(:,i) would be some matrices (but with growing columnsize..size in your case u is growing).
  2 件のコメント
Ondrej 2012 年 2 月 11 日
Well, the difference is that X(i) means X is a vector and X(:,i) is a matrix (meaning the i-th column of X). See
Btw. if you do for loops with variables growing inside, consider preallocating:
As for your code, it doesn't work for me because of the symbolic variables in betainv, so I think I can't help you with that.


その他の回答 (0 件)


Find more on Particle & Nuclear Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by