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!