CPF_PREDICT Do prediction in cpf. [INPUT PARAMETERS] type_predict: 1-predict voltage; 2-predict lambda loadvarloc: (in internal bus numbering) [OUTPUT PARAMETERS] J: jacobian matrix for the given voltage profile (before prediction) created by Rui Bo on 2007/11/12
0001 function [V_predicted, lambda_predicted, J] = cpf_predict(Ybus, ref, pv, pq, V, lambda, sigma, type_predict, initQPratio, loadvarloc, flag_lambdaIncrease) 0002 %CPF_PREDICT Do prediction in cpf. 0003 % [INPUT PARAMETERS] 0004 % type_predict: 1-predict voltage; 2-predict lambda 0005 % loadvarloc: (in internal bus numbering) 0006 % [OUTPUT PARAMETERS] 0007 % J: jacobian matrix for the given voltage profile (before prediction) 0008 % created by Rui Bo on 2007/11/12 0009 0010 % MATPOWER 0011 % $Id: cpf_predict.m,v 1.4 2010/04/26 19:45:26 ray Exp $ 0012 % by Rui Bo 0013 % Copyright (c) 2009-2010 by Rui Bo 0014 % 0015 % This file is part of MATPOWER. 0016 % See http://www.pserc.cornell.edu/matpower/ for more info. 0017 % 0018 % MATPOWER is free software: you can redistribute it and/or modify 0019 % it under the terms of the GNU General Public License as published 0020 % by the Free Software Foundation, either version 3 of the License, 0021 % or (at your option) any later version. 0022 % 0023 % MATPOWER is distributed in the hope that it will be useful, 0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0026 % GNU General Public License for more details. 0027 % 0028 % You should have received a copy of the GNU General Public License 0029 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0030 % 0031 % Additional permission under GNU GPL version 3 section 7 0032 % 0033 % If you modify MATPOWER, or any covered work, to interface with 0034 % other modules (such as MATLAB code and MEX-files) available in a 0035 % MATLAB(R) or comparable environment containing parts covered 0036 % under other licensing terms, the licensors of MATPOWER grant 0037 % you additional permission to convey the resulting work. 0038 0039 %% set up indexing 0040 npv = length(pv); 0041 npq = length(pq); 0042 0043 pv_bus = ~isempty(find(pv == loadvarloc)); 0044 0045 %% form current variable set from given voltage 0046 x_current = [ angle(V([pv;pq])); 0047 abs(V(pq)); 0048 lambda]; 0049 0050 %% evaluate Jacobian 0051 [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V); 0052 0053 j11 = real(dSbus_dVa([pv; pq], [pv; pq])); 0054 j12 = real(dSbus_dVm([pv; pq], pq)); 0055 j21 = imag(dSbus_dVa(pq, [pv; pq])); 0056 j22 = imag(dSbus_dVm(pq, pq)); 0057 0058 J = [ j11 j12; 0059 j21 j22; ]; 0060 0061 %% form K 0062 K = zeros(npv+2*npq, 1); 0063 if pv_bus % pv bus 0064 K(find(pv == loadvarloc)) = -1; % corresponding to deltaP 0065 else % pq bus 0066 K(npv + find(pq == loadvarloc)) = -1; % corresponding to deltaP 0067 K(npv + npq + find(pq == loadvarloc)) = -initQPratio; % corresponding to deltaQ 0068 end 0069 0070 %% form e 0071 e = zeros(1, npv+2*npq+1); 0072 if type_predict == 1 % predict voltage 0073 if flag_lambdaIncrease == true 0074 e(npv+2*npq+1) = 1; % dLambda = 1 0075 else 0076 e(npv+2*npq+1) = -1; % dLambda = -1 0077 end 0078 elseif type_predict == 2 % predict lambda 0079 e(npv+npq+find(pq == loadvarloc)) = -1; % dVm = -1 0080 else 0081 fprintf('Error: unknow ''type_predict''.\n'); 0082 pause 0083 end 0084 0085 %% form b 0086 b = zeros(npv+2*npq+1, 1); 0087 b(npv+2*npq+1) = 1; 0088 0089 %% form augmented Jacobian 0090 %NOTE: the use of '-J' instead of 'J' is due to that the definition of 0091 %dP(,dQ) in the textbook is the negative of the definition in MATPOWER. In 0092 %the textbook, dP=Pinj-Pbus; In MATPOWER, dP=Pbus-Pinj. Therefore, the 0093 %Jacobians generated by the two definitions differ only in the sign. 0094 augJ = [-J K; 0095 e ]; 0096 0097 %% calculate predicted variable set 0098 x_predicted = x_current + sigma*(augJ\b); 0099 0100 %% convert variable set to voltage form 0101 V_predicted([ref], 1) = V([ref]); 0102 V_predicted([pv], 1) = abs(V([pv])).* exp(sqrt(-1) * x_predicted([1:npv]) ); 0103 V_predicted([pq], 1) = x_predicted([npv+npq+1:npv+2*npq]).* exp(sqrt(-1) * x_predicted([npv+1:npv+npq]) ); 0104 lambda_predicted = x_predicted(npv+2*npq+1);