Hi, I'm very new to MatLab and I am trying to write a simple flash calculation code, however I am getting the above error. I was wondering if you could help me. I'm not sure what the error is asking.
if true % code
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); endnv0= 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);endif fnkd ~= 0 nv = nv0 - fnk/fnkd; else nv = nv0 + 0.01; endendnv
This is the error I'm getting: Error in FlashCal (line 74) fnk = fnk + ((Zi(i) * (Ki(i)-1))/(nv(Ki(i)-1)+1)); Whre: fnk = sigma(i) Zi(Ki-1)/nv(Ki-1)+1 fnkd = – sigma(i) Zi(Ki-1)^2/(nv(Ki-1)+1)^2
Many Thanks
Best Answer