试图访问nv(2.8); index必须是正整数或逻辑

时间:2014-09-05 15:49:53

标签: matlab

我对MatLab很新,我正在尝试编写一个简单的flash计算代码,但是我收到了上述错误。我想知道你是否可以帮助我。我不确定错误是什么。

Zi = [0.2, 0.1, 0.1, 0.2, 0.2, 0.2]; 
pvi = [190, 72.2 51.6, 20.44, 15.57, 4.956]; 
Ki = [3.8, 1.444, 1.032, 0.4088, 0.3114, 0.09912];
A = 0;
B = 0;
for i = 1:length(Zi)
  A = A + Zi(i)*(Ki(i)-1);
B = B + Zi(i)*((1/Ki(i))-1);
  end
nv0= A/(A+B);
% Display an error message if 0<nv<1
if nv0 > 1 || nv0 < 0 || nv0 ==0
  error('nv guess is incorrect')
end
% Step 2 - Solving Equation 5 - 16 for nv Using Newton-Raphson Method
nv = nv0;
nv0 = nv + .01; % Is this for the first gues abs dev?
itermax = 200;
fnkd = 0;
fnk = 0;
while abs(nv0 - nv) > tol & iter < itermax
  iter = iter + 1;
  nv0 = nv;
for i= 1:length(Zi)
      fnk = fnk + ((Zi(i) * (Ki(i)-1))/(nv(Ki(i)-1)+1));
     fnkd = fnkd +(-1*(Zi(i)*(Ki(i)-1)^2)/(nv(Ki(i)-1)+1)^2);
end
if fnkd ~= 0 
     nv = nv0 - fnk/fnkd;
  else
      nv = nv0 + 0.01;
  end
end
nv

这是我得到的错误:FlashCal中的错误(第74行)fnk = fnk +((Zi(i)*(Ki(i)-1))/(nv(Ki(i)-1) 1));

其中:  fnk = sigma(i)Zi(Ki-1)/ nv(Ki-1)+1 fnkd = - sigma(i)Zi(Ki-1)^ 2 /(nv(Ki-1)+1)^ 2

非常感谢

1 个答案:

答案 0 :(得分:0)

nv(Ki(i)-1)无效。或者你的意思是nv *(Ki(i)-1)或Ki(i)-1应该评估为一个整数,因为你用它来访问位置(Ki(i)-1)的nv。但是,它是2.8,即(3.8-1)