Home > matpower7.0 > extras > syngrid > lib > nsw_gen_Zpr.m

nsw_gen_Zpr

PURPOSE ^

generate the line impedances and form the network admittance matrix

SYNOPSIS ^

function [Zpr] = nsw_gen_Zpr(Zpr_pars, ms)

DESCRIPTION ^

 generate the line impedances and form the network admittance matrix
 Input:
   Zpr_pars - random variable model parameters for Zpr;
   ms - the link numbers [m1,m2,m3]
         m1 - total number of local links
         m2 - total number of rewires inside islands
         m3 - total number of lattice links between islands
 Output:
   Zpr - line impedance vector (magnitude);
 by wzf, 2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Zpr] = nsw_gen_Zpr(Zpr_pars, ms)
0002 % generate the line impedances and form the network admittance matrix
0003 % Input:
0004 %   Zpr_pars - random variable model parameters for Zpr;
0005 %   ms - the link numbers [m1,m2,m3]
0006 %         m1 - total number of local links
0007 %         m2 - total number of rewires inside islands
0008 %         m3 - total number of lattice links between islands
0009 % Output:
0010 %   Zpr - line impedance vector (magnitude);
0011 % by wzf, 2009
0012 
0013 %   SynGrid
0014 %   Copyright (c) 2009, 2017-2018, Electric Power and Energy Systems (EPES) Research Lab
0015 %   by Zhifang Wang, Virginia Commonwealth University
0016 %
0017 %   This file is part of SynGrid.
0018 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0019 
0020 m1 = ms(1); m2 = ms(2); m3 = ms(3);
0021 Zprs = Zpr_rnd(Zpr_pars, sum(ms)); % generate line impedances
0022 Zprs = sort(Zprs,'descend');
0023 
0024 Zprs_m1 = Zprs(1:m1); % local links
0025 tmp = randperm(m1); Zprs_m1 = Zprs_m1(tmp);
0026 
0027 Zprs_m2 = Zprs(m1+1:m1+m2); % rewiring links
0028 tmp = randperm(m2); Zprs_m2 = Zprs_m2(tmp);
0029 
0030 if(m3 > 0)
0031     Zprs_m3 = Zprs(m1+m2+1:sum(ms)); % lattice connection links
0032     tmp = randperm(m3); Zprs_m3 = Zprs_m3(tmp);
0033 else
0034     Zprs_m3 = [];
0035 end
0036 
0037 Zpr = [Zprs_m1; Zprs_m2; Zprs_m3];
0038 pos = find(Zpr<1e-6);
0039 if(~isempty(pos))
0040     Zpr(pos) = 1e-6;
0041 end
0042 
0043 %--------------------------------------------------------------------------
0044 %--------------------------------------------------------------------------
0045 function yout = Zpr_rnd(Zpr_pars, m)
0046 % given the random Var model parameter for line impedances Zpr, generate a
0047 % set of sample data.
0048 % Inputs:
0049 %   Zpr_pars - line impedance parameters,
0050 %               include {model name, model pars}
0051 %   m - total number of line impedances
0052 %Outputs:
0053 %   yout - vector of line impedances (m by 1)
0054 %
0055 % by wzf, 2009
0056 
0057 
0058 rv_model = Zpr_pars{1};
0059 rv_pars = Zpr_pars{2};
0060 
0061 % switch rv_model
0062 %     case 'GAMMA'
0063 %         a = rv_pars(1); b = rv_pars(2);
0064 %         yout = gamrnd(a,b,m,1);
0065 %     case 'GP'
0066 %         k = rv_pars(1); d = rv_pars(2); t = rv_pars(3);
0067 %         yout = gprnd(k,d,t,m,1);
0068 %     case 'LOGN'
0069 %         mu = rv_pars(1); d = rv_pars(2);
0070 %         yout = lognrnd(mu,d,m,1);
0071 %     case 'LOGN-clip'
0072         mu = rv_pars(1); d = rv_pars(2); Zmax = rv_pars(3);
0073         yout = lognclip_rnd(mu,d,Zmax, m,1);
0074 %     case 'DPLN'
0075 %         a = rv_pars(1); b = rv_pars(2);
0076 %         mu = rv_pars(3); d = rv_pars(4);
0077 %         yout = dpln_rnd(a,b,mu,d, m,1);
0078 %     case 'DPLN-clip'
0079 %         a = rv_pars(1); b = rv_pars(2);
0080 %         mu = rv_pars(3); d = rv_pars(4); Zmax = rv_pars(5);
0081 %         yout = dplnclip_rnd(a,b,mu,d, Zmax, m,1);
0082 %     otherwise
0083 %         disp(['There is not a Zpr model as "', rv_model,'" designed in this program!']);
0084 %         yout = [];
0085 % end
0086 
0087 %--------------------------------------------------------------------------
0088 %--------------------------------------------------------------------------
0089 function yout = lognclip_rnd(mu,d,Zmax, m,n)
0090 % generate sample data with distribution of LogNormal-clipped
0091 y = sg_lognrnd(mu,d,m,n);
0092 yout = Zmax*(1-exp(-y/Zmax));
0093 
0094 %--------------------------------------------------------------------------
0095 function yout = dplnclip_rnd(a,b,mu,d, Zmax, m,n)
0096 % generate sample data with distribution of DPLN-clip
0097 y = dpln_rnd(a,b,mu,d,m,n);
0098 yout = Zmax*(1-exp(-y/Zmax));
0099 
0100 %--------------------------------------------------------------------------
0101 function yout = dpln_rnd(alph,bta,mu,tau, m,n)
0102 % generate sample data with distribution of DPLN
0103 pr = bta/(alph+bta);
0104 z = binornd(1,pr,m,n);
0105 ug = normrnd(mu,tau,m,n);
0106 wg = (z+(z-1)*alph/bta).*sg_exprnd(1/alph,m,n); % note: Matlab EXP-pdf use 1/alph
0107 yout = exp(ug+wg);

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005