help in this plz
1 回表示 (過去 30 日間)
古いコメントを表示
I have Values like this
C2 = 0.10;
C3 = 0.10;
C4 = 0.20;
C5 = 0.20;
C6 = 0.20;
P1=190;
P2=72.2;
P3=51.6;
P4=20.44;
P5=15.57;
P6= 4.956;
K1=P1/P;
K2=P2/P;
K3=P3/P;
K4=P4/P;
K5=P5/P;
K6=P6/P;
note :- this is very lengthy and I want to make it shorter and calculating like this
for c = [0.20,0.10,0.10,0.20,0.20,0.20]
for P = [190,72.2,51.6,20.44,15.57,4.956]
PG = 50;
K = (P/PG);
A = c*(K-1);
B = c*(K-1)/K;
nv = A/(A-B);
disp(nv)
end
end
Can I use these code to calculate it in a simpler way or I am need to change the code , suggest plz
thanks
1 件のコメント
Image Analyst
2012 年 2 月 19 日
Inside your loop, the c's cancel out in the nv division, so nv, K, and PG don't depend on c at all so why are they in a loop over c? Also, in the first chunk of code, I assume P1 = P(1), so what is P? You can't do K(1) = P(1) ./ P because the dimensions don't match so I have no idea what you want to do.
回答 (2 件)
Walter Roberson
2012 年 2 月 19 日
Yes, you can use loops such as you show. Your "for" syntax is valid.
You might want to store the answers after you calculate them, though.
3 件のコメント
Jan
2012 年 2 月 19 日
The code runs fine and "nv" is calculated - but only the last value is stored. Because "nv" does not depend on "c" at all, the outer loop can be omitted.
Jan
2012 年 2 月 19 日
You nv does not depend on c, such that the calculation of nv can be simplified to:
nv = K / (K-1);
or:
nv = 1 / (1 - PG/P);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!