Home > matpower6.0 > t > t_jacobian.m

t_jacobian

PURPOSE ^

T_JACOBIAN Numerical tests of partial derivative code.

SYNOPSIS ^

function t_jacobian(quiet)

DESCRIPTION ^

T_JACOBIAN  Numerical tests of partial derivative code.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_jacobian(quiet)
0002 %T_JACOBIAN  Numerical tests of partial derivative code.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 t_begin(28, quiet);
0017 
0018 casefile = 'case30';
0019 
0020 %% define named indices into bus, gen, branch matrices
0021 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0022     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0023 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0024     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0025     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0026 
0027 %% run powerflow to get solved case
0028 mpopt = mpoption('verbose', 0, 'out.all', 0);
0029 mpc = loadcase(casefile);
0030 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0031 
0032 %% switch to internal bus numbering and build admittance matrices
0033 [i2e, bus, gen, branch] = ext2int(bus, gen, branch);
0034 [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch);
0035 Ybus_full   = full(Ybus);
0036 Yf_full     = full(Yf);
0037 Yt_full     = full(Yt);
0038 Vm = bus(:, VM);
0039 Va = bus(:, VA) * pi/180;
0040 V = Vm .* exp(1j * Va);
0041 f = branch(:, F_BUS);       %% list of "from" buses
0042 t = branch(:, T_BUS);       %% list of "to" buses
0043 nl = length(f);
0044 nb = length(V);
0045 pert = 1e-8;
0046 
0047 %%-----  check dSbus_dV code  -----
0048 %% full matrices
0049 [dSbus_dVm_full, dSbus_dVa_full] = dSbus_dV(Ybus_full, V);
0050 
0051 %% sparse matrices
0052 [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V);
0053 dSbus_dVm_sp = full(dSbus_dVm);
0054 dSbus_dVa_sp = full(dSbus_dVa);
0055 
0056 %% compute numerically to compare
0057 Vmp = (Vm*ones(1,nb) + pert*eye(nb,nb)) .* (exp(1j * Va) * ones(1,nb));
0058 Vap = (Vm*ones(1,nb)) .* (exp(1j * (Va*ones(1,nb) + pert*eye(nb,nb))));
0059 num_dSbus_dVm = full( (Vmp .* conj(Ybus * Vmp) - V*ones(1,nb) .* conj(Ybus * V*ones(1,nb))) / pert );
0060 num_dSbus_dVa = full( (Vap .* conj(Ybus * Vap) - V*ones(1,nb) .* conj(Ybus * V*ones(1,nb))) / pert );
0061 
0062 t_is(dSbus_dVm_sp, num_dSbus_dVm, 5, 'dSbus_dVm (sparse)');
0063 t_is(dSbus_dVa_sp, num_dSbus_dVa, 5, 'dSbus_dVa (sparse)');
0064 t_is(dSbus_dVm_full, num_dSbus_dVm, 5, 'dSbus_dVm (full)');
0065 t_is(dSbus_dVa_full, num_dSbus_dVa, 5, 'dSbus_dVa (full)');
0066 
0067 %%-----  check dSbr_dV code  -----
0068 %% full matrices
0069 [dSf_dVa_full, dSf_dVm_full, dSt_dVa_full, dSt_dVm_full, Sf, St] = dSbr_dV(branch, Yf_full, Yt_full, V);
0070 
0071 %% sparse matrices
0072 [dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St] = dSbr_dV(branch, Yf, Yt, V);
0073 dSf_dVa_sp = full(dSf_dVa);
0074 dSf_dVm_sp = full(dSf_dVm);
0075 dSt_dVa_sp = full(dSt_dVa);
0076 dSt_dVm_sp = full(dSt_dVm);
0077 
0078 %% compute numerically to compare
0079 Vmpf = Vmp(f,:);
0080 Vapf = Vap(f,:);
0081 Vmpt = Vmp(t,:);
0082 Vapt = Vap(t,:);
0083 Sf2 = (V(f)*ones(1,nb)) .* conj(Yf * V*ones(1,nb));
0084 St2 = (V(t)*ones(1,nb)) .* conj(Yt * V*ones(1,nb));
0085 Smpf = Vmpf .* conj(Yf * Vmp);
0086 Sapf = Vapf .* conj(Yf * Vap);
0087 Smpt = Vmpt .* conj(Yt * Vmp);
0088 Sapt = Vapt .* conj(Yt * Vap);
0089 
0090 num_dSf_dVm = full( (Smpf - Sf2) / pert );
0091 num_dSf_dVa = full( (Sapf - Sf2) / pert );
0092 num_dSt_dVm = full( (Smpt - St2) / pert );
0093 num_dSt_dVa = full( (Sapt - St2) / pert );
0094 
0095 t_is(dSf_dVm_sp, num_dSf_dVm, 5, 'dSf_dVm (sparse)');
0096 t_is(dSf_dVa_sp, num_dSf_dVa, 5, 'dSf_dVa (sparse)');
0097 t_is(dSt_dVm_sp, num_dSt_dVm, 5, 'dSt_dVm (sparse)');
0098 t_is(dSt_dVa_sp, num_dSt_dVa, 5, 'dSt_dVa (sparse)');
0099 t_is(dSf_dVm_full, num_dSf_dVm, 5, 'dSf_dVm (full)');
0100 t_is(dSf_dVa_full, num_dSf_dVa, 5, 'dSf_dVa (full)');
0101 t_is(dSt_dVm_full, num_dSt_dVm, 5, 'dSt_dVm (full)');
0102 t_is(dSt_dVa_full, num_dSt_dVa, 5, 'dSt_dVa (full)');
0103 
0104 %%-----  check dAbr_dV code  -----
0105 %% full matrices
0106 [dAf_dVa_full, dAf_dVm_full, dAt_dVa_full, dAt_dVm_full] = ...
0107                         dAbr_dV(dSf_dVa_full, dSf_dVm_full, dSt_dVa_full, dSt_dVm_full, Sf, St);
0108 %% sparse matrices
0109 [dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm] = ...
0110                         dAbr_dV(dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St);
0111 dAf_dVa_sp = full(dAf_dVa);
0112 dAf_dVm_sp = full(dAf_dVm);
0113 dAt_dVa_sp = full(dAt_dVa);
0114 dAt_dVm_sp = full(dAt_dVm);
0115 
0116 %% compute numerically to compare
0117 num_dAf_dVm = full( (abs(Smpf).^2 - abs(Sf2).^2) / pert );
0118 num_dAf_dVa = full( (abs(Sapf).^2 - abs(Sf2).^2) / pert );
0119 num_dAt_dVm = full( (abs(Smpt).^2 - abs(St2).^2) / pert );
0120 num_dAt_dVa = full( (abs(Sapt).^2 - abs(St2).^2) / pert );
0121 
0122 t_is(dAf_dVm_sp, num_dAf_dVm, 4, 'dAf_dVm (sparse)');
0123 t_is(dAf_dVa_sp, num_dAf_dVa, 4, 'dAf_dVa (sparse)');
0124 t_is(dAt_dVm_sp, num_dAt_dVm, 4, 'dAt_dVm (sparse)');
0125 t_is(dAt_dVa_sp, num_dAt_dVa, 4, 'dAt_dVa (sparse)');
0126 t_is(dAf_dVm_full, num_dAf_dVm, 4, 'dAf_dVm (full)');
0127 t_is(dAf_dVa_full, num_dAf_dVa, 4, 'dAf_dVa (full)');
0128 t_is(dAt_dVm_full, num_dAt_dVm, 4, 'dAt_dVm (full)');
0129 t_is(dAt_dVa_full, num_dAt_dVa, 4, 'dAt_dVa (full)');
0130 
0131 %%-----  check dIbr_dV code  -----
0132 %% full matrices
0133 [dIf_dVa_full, dIf_dVm_full, dIt_dVa_full, dIt_dVm_full, If, It] = dIbr_dV(branch, Yf_full, Yt_full, V);
0134 
0135 %% sparse matrices
0136 [dIf_dVa, dIf_dVm, dIt_dVa, dIt_dVm, If, It] = dIbr_dV(branch, Yf, Yt, V);
0137 dIf_dVa_sp = full(dIf_dVa);
0138 dIf_dVm_sp = full(dIf_dVm);
0139 dIt_dVa_sp = full(dIt_dVa);
0140 dIt_dVm_sp = full(dIt_dVm);
0141 
0142 %% compute numerically to compare
0143 num_dIf_dVm = full( (Yf * Vmp - Yf * V*ones(1,nb)) / pert );
0144 num_dIf_dVa = full( (Yf * Vap - Yf * V*ones(1,nb)) / pert );
0145 num_dIt_dVm = full( (Yt * Vmp - Yt * V*ones(1,nb)) / pert );
0146 num_dIt_dVa = full( (Yt * Vap - Yt * V*ones(1,nb)) / pert );
0147 
0148 t_is(dIf_dVm_sp, num_dIf_dVm, 5, 'dIf_dVm (sparse)');
0149 t_is(dIf_dVa_sp, num_dIf_dVa, 5, 'dIf_dVa (sparse)');
0150 t_is(dIt_dVm_sp, num_dIt_dVm, 5, 'dIt_dVm (sparse)');
0151 t_is(dIt_dVa_sp, num_dIt_dVa, 5, 'dIt_dVa (sparse)');
0152 t_is(dIf_dVm_full, num_dIf_dVm, 5, 'dIf_dVm (full)');
0153 t_is(dIf_dVa_full, num_dIf_dVa, 5, 'dIf_dVa (full)');
0154 t_is(dIt_dVm_full, num_dIt_dVm, 5, 'dIt_dVm (full)');
0155 t_is(dIt_dVa_full, num_dIt_dVa, 5, 'dIt_dVa (full)');
0156 
0157 t_end;

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005