% function [Ki,K] = area2PI_dist (A0,A1,A2,A3,Kmax); % % Function araa2PI calculates parameters of the PI controller: % % u = (Ki/s + K) * e % % from the measured areas of the process A0 to A3 (A0 is the process steady-state gain) % for "optimal" disturbance rejection. % The parameter Kmax represents the highest allowed open-loop gain K*A0 function [Ki,K] = area2PI_dist (A0,A1,A2,A3,Kmax); Ceta1 = A0*A0*A3 - 2*A0*A1*A2 + A1*A1*A1; Ceta2 = A1*A2 - A0*A3; if (Ceta1 == 0) Num = A3; % Numerator Den = 2*(A1*A2-A0*A3); % Denominator if (Num == 0) K = 0; elseif (Den == 0) if (A0 ~= 0) K = Kmax/A0; else K = Kmax; end; else K = Num/Den; end; Tmp = K*A0; % Nominal gain if (Tmp > Kmax) | (Tmp < 0) K = Kmax/A0; end; else K = (Ceta2 - sign(Ceta2)*A1*sqrt(A2*A2-A1*A3))/Ceta1; Tmp = K*A0; % Nominal gain if (Tmp > Kmax) | (Tmp < 0) K = Kmax/A0; end; end; Ki = 0.5*(K*A0 + 1)*(K*A0 + 1)/A1;