Dear MATPOWER developers,

  My name is Piero Carlo dos Reis and I am the MAVT student who has previously 
asked you for material on the courses in electrical engineering you hold at ETH.
   Since my current semester project involves an optimization code for AC 
newton Raphson procedure, I have been asked by my professor to validate it. I 
have followed the procedure illustrated by Prof. Shahidehpour in his paper 
"Security-Constrained Unit Commitment With AC Constraints" in order to model 
the Jacobian matrix (in which I also included transformer variables such as tap 
and transformer angle). A validation method advised to me by my Professor and 
which I have tried to pursue is the use of AC opf with matpower to solve a case 
study from internet (and to try to get same results with my code). I have 
download matpower version 6. However, when solving case studies (such as case 
WB5 which I am annexing together with a text file of the matpower solution), I 
get that the sum of Q generation is different from the sum of Q load + sum of Q 
losses (in WB5 matpower ac opf solution, it is evident due to the fact that the 
result is sum Q generation is -7 p.u., sum Q load is 50 p.u. and sum Q losses 
is 35.30 p.u.). Would you have an explanation to this results and to how 
matpower solves the Q nodal balance of power/Q mismatch? In another case study 
I choose to run, case5, I got the also that this equality was not true, 
although the difference is not as evident as in WB5. I am also annexing the 
results from my code and from matpower in text files (I evaluated the losses as 
sum of Gen - sum of load for simplicity.)

I thank you for your attention, sincerely, Piero carlo dos Reis
function mpc = WB5
%% 5 bus case in MATPOWER format
%  W. A. Bukhsh, Feb 2013 
%%   References:
%   [1] W. A. Bukhsh, Andreas Grothey, Ken McKinnon, Paul trodden, "Local 
Solutions of Optimal Power Flow Problem"
%       submitted to IEEE Transactions on Power Systems, 2013
%   [2] W. A. Bukhsh, Andreas Grothey, Ken McKinnon, Paul trodden, "Local 
Solutions of Optimal Power Flow Problem"
%       Technical Report ERGO, 2011
%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%-----  Power Flow Data  -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
%       bus_i   type    Pd      Qd      Gs      Bs      area    Vm      Va      
baseKV  zone    Vmax    Vmin
mpc.bus = [
    1   3       0       0       0       0       0       0       0   345 1       
1.05    0.95;
    2   1       130     20      0       0       0       0     0   345   1       
1.05    0.95;
        3       1       130     20      0       0       0       0     0         
345     1       1.05    0.95;
        4       1       65  10  0       0       0       0     0         345     
1       1.05    0.95;
        5       2       0       0       0       0       0       0     0         
345     1       1.05    0.95;   
%       1       3       0       0       0       0       1       1.0     0   345 
1       1.05    0.95;
%     2 1       130     20      0       0       1       1.0     0   345 1       
1.05    0.95;
%       3       1       130     20      0       0       1       1.0     0       
345     1       1.05    0.95;
%       4       1       65  10  0       0       1       1.0     0       345     
1       1.05    0.95;
%       5       2       0       0       0       0       1       1.0     0       
345     1       1.05    0.95;   
%       2       1       130     20      0       0       1       1.0   -10       
345     1       1.05    0.95;
%       3       1       130     20      0       0       1       1.0   -20       
345     1       1.05    0.95;
%       4       1       65  10  0       0       1       1.0   -135      345     
1       1.05    0.95;
%       5       2       0       0       0       0       1       1.0   -140      
345     1       1.05    0.95;   

    ];
%% generator data
%       bus     Pg      Qg      Qmax    Qmin    Vg      mBase   status  Pmax    
Pmin    Pc1     Pc2     Qc1min  Qc1max  Qc2min  Qc2max  ramp_agc        ramp_10 
ramp_30 ramp_q  apf
mpc.gen = [
        1       263  30 1800    -30     1       100     1       5000    0       
0       0       0       0       0       0       0       0       0       0       
0;
        5       30   30 1800    -30     1       100     1       5000    0       
0       0       0       0       0       0       0       0       0       0       
0;
  
        
];

%% branch data
%       fbus    tbus    r       x       b       rateA   rateB   rateC   ratio   
angle   status  angmin  angmax
mpc.branch = [
        1       2       0.04    0.09       0.0     2500 2500    2500    0       
0       1       -360    360;
        1       3       0.05    0.10       0.0     2500 2500    2500    0       
0       1       -360    360;
        2       4       0.55    0.90       0.45    2500 2500    2500    0       
0       1       -360    360;
        3       5       0.55    0.90       0.45    2500 2500    2500    0       
0       1       -360    360;
        4       5       0.06    0.1        0.0     2500 2500    2500    0       
0       1       -360    360;
        2       3       0.07    0.09       0.0     2500 2500    2500    0       
0       1       -360    360;
        
];

%%-----  OPF Data  -----%%
%% area data
%       area    refbus
mpc.areas = [
        1       5;
];

%% generator cost data
%       1       startup shutdown        n       x1      y1      ...     xn      
yn
%       2       startup shutdown        n       c(n-1)  ...     c0
mpc.gencost = [
%       2       2       0       3       0       4.00    0;
    2   2       0       3       0       1.00    0;
        2       2       0       3       0       1.00    0;
        
];


mpc.traf = [];

%  return;
with P line limit type of constraint
MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 0.30 seconds
Objective Function Value = 342.31 $/hr
================================================================================
|     System Summary                                                           |
================================================================================

How many?                How much?              P (MW)            Q (MVAr)
---------------------    -------------------  -------------  -----------------
Buses              5     Total Gen Capacity   10000.0         -60.0 to 3600.0
Generators         2     On-line Capacity     10000.0         -60.0 to 3600.0
Committed Gens     2     Generation (actual)    342.3              -7.0
Loads              3     Load                   325.0              50.0
  Fixed            3       Fixed                325.0              50.0
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)        17.31             35.31
Transformers       0     Branch Charging (inj)     -               92.3
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   0.988 p.u. @ bus 3          1.050 p.u. @ bus 1   
Voltage Angle      -6.66 deg   @ bus 3          0.00 deg   @ bus 1   
P Losses (I^2*R)             -                  7.13 MW    @ line 1-3
Q Losses (I^2*X)             -                 15.83 MVAr  @ line 1-2
Lambda P            1.00 $/MWh @ bus 5          1.12 $/MWh @ bus 3   
Lambda Q           -0.05 $/MWh @ bus 4          0.01 $/MWh @ bus 3   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.050    0.000*   263.64     22.94       -         -       1.000     -
    2  0.992   -6.577       -         -      130.00     20.00     1.116   0.007
    3  0.988   -6.661       -         -      130.00     20.00     1.124   0.007
    4  1.019   -6.424       -         -       65.00     10.00     1.075  -0.053
    5  1.050   -2.494     78.67    -29.94       -         -       1.000  -0.047
                        --------  --------  --------  --------
               Total:    342.31     -7.00    325.00     50.00

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    138.59     13.55   -131.55      2.28     7.035     15.83
   2      1      3    125.05      9.39   -117.92      4.87     7.132     14.26
   3      2      4     -1.55    -24.20      1.59    -21.27     0.037      0.06
   4      3      5     -8.98    -22.96      9.44    -23.06     0.460      0.75
   5      4      5    -66.59     11.27     69.22     -6.88     2.634      4.39
   6      2      3      3.11      1.92     -3.10     -1.91     0.009      0.01
                                                             --------  --------
                                                    Total:    17.307     35.31

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.950  1.050  1.050    23.166
    5      -      0.950  1.050  1.050     9.544

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                 Reactive Power Limits
  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu
----  -----   -------   --------  --------  --------  -------
   2     5      0.047    -30.00    -29.94   1800.00      -   





with S line limit type of constraint
> runopf(WB5)

MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 0.27 seconds
Objective Function Value = 342.30 $/hr
================================================================================
|     System Summary                                                           |
================================================================================
 
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)        17.31             35.30
Transformers       0     Branch Charging (inj)     -               92.3
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   0.988 p.u. @ bus 3          1.050 p.u. @ bus 1   
Voltage Angle      -6.66 deg   @ bus 3          0.00 deg   @ bus 1   
P Losses (I^2*R)             -                  7.13 MW    @ line 1-3
Q Losses (I^2*X)             -                 15.82 MVAr  @ line 1-2
Lambda P            1.00 $/MWh @ bus 5          1.12 $/MWh @ bus 3   
Lambda Q           -0.05 $/MWh @ bus 4          0.01 $/MWh @ bus 3   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.050    0.000*   263.55     22.97       -         -       1.000     -
    2  0.992   -6.574       -         -      130.00     20.00     1.116   0.007
    3  0.988   -6.658       -         -      130.00     20.00     1.124   0.008
    4  1.019   -6.394       -         -       65.00     10.00     1.075  -0.052
    5  1.050   -2.462     78.76    -29.98       -         -       1.000  -0.046
                        --------  --------  --------  --------
               Total:    342.30     -7.00    325.00     50.00

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    138.54     13.57   -131.51      2.25     7.030     15.82
   2      1      3    125.01      9.41   -117.88      4.85     7.127     14.25
   3      2      4     -1.59    -24.18      1.63    -21.29     0.037      0.06
   4      3      5     -9.02    -22.93      9.49    -23.08     0.464      0.76
   5      4      5    -66.63     11.29     69.27     -6.89     2.637      4.40
   6      2      3      3.10      1.93     -3.09     -1.91     0.009      0.01
                                                             --------  --------
                                                    Total:    17.305     35.30

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.950  1.050  1.050    23.410
    5      -      0.950  1.050  1.050     9.461

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                 Reactive Power Limits
  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu
----  -----   -------   --------  --------  --------  -------
   2     5      0.046    -30.00    -29.98   1800.00      -   
WITH P LINE LIMIT CONSTRAINT
MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 0.91 seconds
Objective Function Value = 10067.77 $/hr
================================================================================
|     System Summary                                                           |
================================================================================

How many?                How much?              P (MW)            Q (MVAr)
---------------------    -------------------  -------------  -----------------
Buses              5     Total Gen Capacity    1530.0       -1147.5 to 1147.5
Generators         5     On-line Capacity      1530.0       -1147.5 to 1147.5
Committed Gens     5     Generation (actual)   1006.8             387.4
Loads              3     Load                  1000.0             328.7
  Fixed            3       Fixed               1000.0             328.7
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)         6.78             67.77
Transformers       0     Branch Charging (inj)     -                9.1
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   1.060 p.u. @ bus 3          1.100 p.u. @ bus 1   
Voltage Angle      -5.42 deg   @ bus 3          0.00 deg   @ bus 5   
P Losses (I^2*R)             -                  3.71 MW    @ line 1-2
Q Losses (I^2*X)             -                 37.11 MVAr  @ line 1-2
Lambda P           10.00 $/MWh @ bus 5         10.20 $/MWh @ bus 3   
Lambda Q            0.00 $/MWh @ bus 5          0.07 $/MWh @ bus 2   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.100    0.000*   568.89    171.04       -         -      10.000     -
    2  1.060   -5.022       -         -      300.00     98.61    10.189   0.067
    3  1.060   -5.424     40.00     29.99    300.00     98.61    10.204   0.067
    4  1.085   -2.756    200.00    149.98    400.00    131.47    10.101   0.023
    5  1.100    0.002    197.89     36.38       -         -      10.000     -
                        --------  --------  --------  --------
               Total:   1006.78    387.40   1000.00    328.69

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    376.71    133.33   -373.00    -97.05     3.711     37.11
   2      1      4    192.71     38.59   -191.74    -29.66     0.971      9.71
   3      1      5     -0.53     -0.88      0.53     -2.90     0.000      0.00
   4      2      3     73.00     -1.56    -72.95     -0.01     0.051      0.51
   5      3      4   -187.05    -68.61    188.10     78.32     1.049     10.49
   6      4      5   -196.36    -30.14    197.36     39.29     0.995      9.95
                                                             --------  --------
                                                    Total:     6.777     67.77

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.900  1.100  1.100   100.311
    5      -      0.900  1.100  1.100    32.647

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                  Active Power Limits
  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -         0.00     40.00     40.00     0.204
   4     4       -         0.00    200.00    200.00     0.101

 Gen   Bus                 Reactive Power Limits
  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -       -30.00     29.99     30.00     0.067
   4     4       -      -150.00    149.98    150.00     0.023
>> 





WITH S LINE LIMIT CONSTRAINT
MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 7.85 seconds
Objective Function Value = 10067.77 $/hr
================================================================================
|     System Summary                                                           |
================================================================================

How many?                How much?              P (MW)            Q (MVAr)
---------------------    -------------------  -------------  -----------------
Buses              5     Total Gen Capacity    1530.0       -1147.5 to 1147.5
Generators         5     On-line Capacity      1530.0       -1147.5 to 1147.5
Committed Gens     5     Generation (actual)   1006.8             387.4
Loads              3     Load                  1000.0             328.7
  Fixed            3       Fixed               1000.0             328.7
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)         6.78             67.77
Transformers       0     Branch Charging (inj)     -                9.1
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   1.060 p.u. @ bus 3          1.100 p.u. @ bus 1   
Voltage Angle      -5.42 deg   @ bus 3          0.00 deg   @ bus 5   
P Losses (I^2*R)             -                  3.71 MW    @ line 1-2
Q Losses (I^2*X)             -                 37.11 MVAr  @ line 1-2
Lambda P           10.00 $/MWh @ bus 5         10.21 $/MWh @ bus 3   
Lambda Q            0.00 $/MWh @ bus 5          0.07 $/MWh @ bus 2   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.100    0.000*   568.47    170.18       -         -      10.000     -
    2  1.060   -5.022       -         -      300.00     98.61    10.190   0.068
    3  1.060   -5.424     40.00     30.00    300.00     98.61    10.205   0.067
    4  1.085   -2.756    200.00    149.99    400.00    131.47    10.101   0.023
    5  1.100    0.003    198.31     37.23       -         -      10.000     -
                        --------  --------  --------  --------
               Total:   1006.78    387.40   1000.00    328.69

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    376.69    133.30   -372.98    -97.02     3.711     37.11
   2      1      4    192.68     38.52   -191.71    -29.60     0.971      9.71
   3      1      5     -0.90     -1.63      0.90     -2.15     0.000      0.00
   4      2      3     72.98     -1.59    -72.93      0.02     0.051      0.51
   5      3      4   -187.07    -68.63    188.12     78.35     1.049     10.49
   6      4      5   -196.41    -30.23    197.41     39.38     0.995      9.95
                                                             --------  --------
                                                    Total:     6.777     67.77

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.900  1.100  1.100   101.589
    5      -      0.900  1.100  1.100    31.423

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                  Active Power Limits
  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -         0.00     40.00     40.00     0.205
   4     4       -         0.00    200.00    200.00     0.101

 Gen   Bus                 Reactive Power Limits
  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -       -30.00     30.00     30.00     0.067
   4     4       -      -150.00    149.99    150.00     0.023
>> 






MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 1.70 seconds
Objective Function Value = 10067.77 $/hr
================================================================================
|     System Summary                                                           |
================================================================================

How many?                How much?              P (MW)            Q (MVAr)
---------------------    -------------------  -------------  -----------------
Buses              5     Total Gen Capacity    1530.0       -1147.5 to 1147.5
Generators         5     On-line Capacity      1530.0       -1147.5 to 1147.5
Committed Gens     5     Generation (actual)   1006.8             387.4
Loads              3     Load                  1000.0             328.7
  Fixed            3       Fixed               1000.0             328.7
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)         6.78             67.77
Transformers       0     Branch Charging (inj)     -                9.1
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   1.060 p.u. @ bus 3          1.100 p.u. @ bus 1   
Voltage Angle      -2.67 deg   @ bus 3          2.76 deg   @ bus 5   
P Losses (I^2*R)             -                  3.71 MW    @ line 1-2
Q Losses (I^2*X)             -                 37.11 MVAr  @ line 1-2
Lambda P           10.00 $/MWh @ bus 5         10.21 $/MWh @ bus 3   
Lambda Q            0.00 $/MWh @ bus 5          0.07 $/MWh @ bus 2   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.100    2.756    568.47    170.18       -         -      10.000     -
    2  1.060   -2.266       -         -      300.00     98.61    10.190   0.068
    3  1.060   -2.668     40.00     30.00    300.00     98.61    10.205   0.067
    4  1.085    0.000*   200.00    149.99    400.00    131.47    10.101   0.023
    5  1.100    2.759    198.31     37.23       -         -      10.000     -
                        --------  --------  --------  --------
               Total:   1006.78    387.40   1000.00    328.69

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    376.69    133.30   -372.98    -97.02     3.711     37.11
   2      1      4    192.68     38.52   -191.71    -29.60     0.971      9.71
   3      1      5     -0.90     -1.63      0.90     -2.15     0.000      0.00
   4      2      3     72.98     -1.59    -72.93      0.02     0.051      0.51
   5      3      4   -187.07    -68.63    188.12     78.35     1.049     10.49
   6      4      5   -196.41    -30.23    197.41     39.38     0.995      9.95
                                                             --------  --------
                                                    Total:     6.777     67.77

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.900  1.100  1.100   101.589
    5      -      0.900  1.100  1.100    31.423

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                  Active Power Limits
  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -         0.00     40.00     40.00     0.205
   4     4       -         0.00    200.00    200.00     0.101

 Gen   Bus                 Reactive Power Limits
  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu
----  -----   -------   --------  --------  --------  -------
   1     3       -       -30.00     30.00     30.00     0.067
   4     4       -      -150.00    149.99    150.00     0.023


MATPOWER Version 6.0, 16-Dec-2016 -- AC Optimal Power Flow
MATPOWER Interior Point Solver -- MIPS, Version 1.2.2, 16-Dec-2016
 (using built-in linear solver)
Converged!

Converged in 0.38 seconds
Objective Function Value = 10010.55 $/hr
================================================================================
|     System Summary                                                           |
================================================================================

How many?                How much?              P (MW)            Q (MVAr)
---------------------    -------------------  -------------  -----------------
Buses              5     Total Gen Capacity    1530.0       -1147.5 to 1147.5
Generators         5     On-line Capacity      1530.0       -1147.5 to 1147.5
Committed Gens     5     Generation (actual)   1001.1             330.0
Loads              3     Load                  1000.0             328.7
  Fixed            3       Fixed               1000.0             328.7
  Dispatchable     0       Dispatchable          -0.0 of -0.0      -0.0
Shunts             0     Shunt (inj)             -0.0               0.0
Branches           6     Losses (I^2 * Z)         1.06             10.56
Transformers       0     Branch Charging (inj)     -                9.3
Inter-ties         0     Total Inter-tie Flow     0.0               0.0
Areas              1

                          Minimum                      Maximum
                 -------------------------  --------------------------------
Voltage Magnitude   1.090 p.u. @ bus 2          1.100 p.u. @ bus 1   
Voltage Angle      -0.38 deg   @ bus 2          1.17 deg   @ bus 5   
P Losses (I^2*R)             -                  0.35 MW    @ line 2-3
Q Losses (I^2*X)             -                  3.51 MVAr  @ line 2-3
Lambda P           10.00 $/MWh @ bus 5         10.06 $/MWh @ bus 2   
Lambda Q           -0.00 $/MWh @ bus 5          0.01 $/MWh @ bus 2   

================================================================================
|     Bus Data                                                                 |
================================================================================
 Bus      Voltage          Generation             Load          Lambda($/MVA-hr)
  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)     P        Q   
----- ------- --------  --------  --------  --------  --------  -------  -------
    1  1.100    1.161    196.28     24.85       -         -      10.000     -
    2  1.090   -0.384       -         -      300.00     98.61    10.056   0.014
    3  1.099    0.521    519.99    175.26    300.00     98.61    10.023     -
    4  1.098    0.000*   200.00    132.98    400.00    131.47    10.041   0.000
    5  1.100    1.167     84.79     -3.12       -         -      10.000     -
                        --------  --------  --------  --------
               Total:   1001.06    329.96   1000.00    328.69

================================================================================
|     Branch Data                                                              |
================================================================================
Brnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  
  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)
-----  -----  -----  --------  --------  --------  --------  --------  --------
   1      1      2    117.82     27.11   -117.48    -24.56     0.340      3.40
   2      1      4     80.47     -0.75    -80.30      1.58     0.163      1.63
   3      1      5     -2.00     -1.51      2.00     -2.27     0.000      0.00
   4      2      3   -182.52    -74.05    182.88     75.33     0.351      3.51
   5      3      4     37.11      1.31    -37.08     -1.79     0.034      0.34
   6      4      5    -82.62      1.71     82.79     -0.84     0.168      1.68
                                                             --------  --------
                                                    Total:     1.056     10.56

================================================================================
|     Voltage Constraints                                                      |
================================================================================
Bus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu
-----  --------   -----  -----  -----   --------
    1      -      0.900  1.100  1.100    12.134
    3      -      0.900  1.099  1.100     1.874
    4      -      0.900  1.098  1.100     0.511
    5      -      0.900  1.100  1.100     4.964

================================================================================
|     Generation Constraints                                                   |
================================================================================
 Gen   Bus                  Active Power Limits
  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu
----  -----   -------   --------  --------  --------  -------
   3     3       -         0.00    519.99    520.00     0.023
   4     4       -         0.00    200.00    200.00     0.041
TT = 

                  V_k      tetha_k2    Pgennode    Qgennode      P_k        Q_k 
     Pd      Qd  
                _______    ________    ________    ________    _______    
_______    __    ______

    Bus n° 1     1.0163          0     3.2349        2.8365    -3.2349    
-2.8365    0          0
    Bus n° 2    0.97025    -5.8782          0             0          3     
0.9861    3     0.9861
    Bus n° 3    0.96908    -6.3348        0.4           0.3        2.6     
0.6861    3     0.9861
    Bus n° 4    0.99688    -3.0982     1.7003           1.5     2.2997    
-0.1853    4     1.3147
    Bus n° 5     1.0127     0.8699     4.7539      -0.38143    -4.7539    
0.38143    0          0


TT2 = 

               Pgen_k     Qgen_k 
               ______    ________

    Gen n°1       0.4         0.3
    Gen n°2         0           0
    Gen n°3    3.2349      2.8365
    Gen n°4    1.7003         1.5
    Gen n°5    4.7539    -0.38143

Total P losses are equal to 8.9152 MW
Total Q losses are equal to 96.8126 MVAr
 
Total cost of unit commitment is 10089.1522
function mpc = case5
% function mpc = case5
%CASE5  Power flow data for modified 5 bus, 5 gen case based on PJM 5-bus system
%   Please see CASEFORMAT for details on the case file format.
%
%   Based on data from ...
%     F.Li and R.Bo, "Small Test Systems for Power System Economic Studies",
%     Proceedings of the 2010 IEEE Power & Energy Society General Meeting

%   Created by Rui Bo in 2006, modified in 2010, 2014.
%   Distributed with permission.

%   MATPOWER

%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%-----  Power Flow Data  -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
%bus_i type     Pd      Qd      Gs      Bs      area    Vm      Va      baseKV  
zone    Vmax    Vmin
mpc.bus = [
%       1       2       0       0       0       0       1       1       0       
230     1       1.1     0.9;
    1   3       0       0       0       0       1       1       0       230     
1       1.1     0.9;
        2       1       300     98.61   0       0       1       1       0       
230     1       1.1     0.9;
        3       2       300     98.61   0       0       1       1       0       
230     1       1.1     0.9;
%       4       3       400     131.47  0       0       1       1       0       
230     1       1.1     0.9;
        4       2       400     131.47  0       0       1       1       0       
230     1       1.1     0.9;
    5   2       0       0       0       0       1       1       0       230     
1       1.1     0.9;
];

%% generator data
% modified version in which i put Qg compatible and nonzero values
%       bus     Pg      Qg           Qmax       Qmin    Vg      mBase   status  
Pmax    Pmin    Pc1     Pc2     Qc1min  Qc1max  Qc2min  Qc2max  ramp_agc        
ramp_10 ramp_30 ramp_q  apf
mpc.gen = [
        3       40      15      30      -30     1       100     1       40      
0       0       0       0       0       0       0       0       0       0       
0       0;
%       1       170     15.73   127.5   -127.5  1       100     1           170 
        0       0       0       0       0       0       0       0       0       
0       0       0;
    1   0       0       127.5   -127.5  1       100     1           170         
0       0       0       0       0       0       0       0       0       0       
0       0
        1       323.49  194.65  390     -390    1       100     1           520 
    0   0       0       0       0       0       0       0       0       0       
0       0;
        4       0       184.12  150          -150       1       100     1       
200     0       0       0       0       0       0       0       0       0       
0       0       0;
        5       466.51  -38.21  450     -450    1       100     1           600 
    0   0       0       0       0       0       0       0       0       0       
0       0;
];


% %     bus     Pg      Qg      Qmax    Qmin    Vg      mBase   status  Pmax    
Pmin    Pc1     Pc2     Qc1min  Qc1max  Qc2min  Qc2max  ramp_agc        ramp_10 
ramp_30 ramp_q  apf
% mpc.gen = [
%       1       40      0       30      -30     1       100     1       40      
0       0       0       0       0       0       0       0       0       0       
0       0;
%       1       170     0       127.5   -127.5  1       100     1       170     
0       0       0       0       0       0       0       0       0       0       
0       0;
%       3       323.49  0       390     -390    1       100     1       520     
0       0       0       0       0       0       0       0       0       0       
0       0;
%       4       0       0       150     -150    1       100     1       200     
0       0       0       0       0       0       0       0       0       0       
0       0;
%       5       466.51  0       450     -450    1       100     1       600     
0       0       0       0       0       0       0       0       0       0       
0       0;
% ];

% %% branch data ORIGINAL VERSION!
% %     fbus    tbus    r       x       b       rateA   rateB   rateC   ratio   
angle   status  angmin  angmax
% mpc.branch = [
%       1       2       0.00281 0.0281  0.00712 400     400     400     0       
0       1       -360    360;
%       1       4       0.00304 0.0304  0.00658 0       0       0       0       
0       1       -360    360;
%       1       5       0.00064 0.0064  0.03126 0       0       0       0       
0       1       -360    360;
%       2       3       0.00108 0.0108  0.01852 0       0       0       0       
0       1       -360    360;
%       3       4       0.00297 0.0297  0.00674 0       0       0       0       
0       1       -360    360;
%       4       5       0.00297 0.0297  0.00674 240     240     240     0       
0       1       -360    360;
% ];


%% branch data
%       fbus    tbus    r       x       b       rateA   rateB   rateC   ratio   
angle   status  angmin  angmax
mpc.branch = [
        1       2       0.00281 0.0281  0.00712 400     400     400     0       
0       1       -360    360;
        1       4       0.00304 0.0304  0.00658 400     0       0       0       
0       1       -360    360;
        1       5       0.00064 0.0064  0.03126 400     0       0       0       
0       1       -360    360;
        2       3       0.00108 0.0108  0.01852 400     0       0       0       
0       1       -360    360;
        3       4       0.00297 0.0297  0.00674 400     0       0       0       
0       1       -360    360;
        4       5       0.00297 0.0297  0.00674 240     240     240     0       
0       1       -360    360;
];

%%-----  OPF Data  -----%%
%% generator cost data
%       1       startup shutdown        n       x1      y1      ...     xn      
yn
%       2       startup shutdown        n       c(n-1)  ...     c0
mpc.gencost = [
    2   0       0       2       10      0;
        2       0       0       2       10      0;
        2       0       0       2       10      0;
        2       0       0       2       10      0;
        2       0       0       2       10      0;
%       2       0       0       2       14      0;
%       2       0       0       2       15      0;
%       2       0       0       2       30      0;
%       2       0       0       2       40      0;
%       2       0       0       2       10      0;
];

% % CORREZIONE DI PER UNIT PER IL BILANCIO DEL CODICE MAIN3
% mpc.bus(:,3)=mpc.bus(:,3)/mpc.baseMVA;
% mpc.bus(:,4)=mpc.bus(:,4)/mpc.baseMVA;
% mpc.gen(:,2)=mpc.gen(:,2)/mpc.baseMVA;
% mpc.gen(:,3)=mpc.gen(:,3)/mpc.baseMVA;
% mpc.gen(:,4)=mpc.gen(:,4)/mpc.baseMVA;
% mpc.gen(:,5)=mpc.gen(:,5)/mpc.baseMVA;
% mpc.gen(:,9)=mpc.gen(:,9)/mpc.baseMVA;
% mpc.branch(:,6)=mpc.branch(:,6)/mpc.baseMVA;

% 
% 
% 
mpc.traf = [];
% 
% %    % BUS PARAMETERS
%    Pd =  mpc.bus(:,3); 
%    Qd =  mpc.bus(:,4); % node vs time matrix 
%    Vmax= mpc.bus(:,12); %vector of mpc.bus (Node, column, time)
%    Vmin= mpc.bus(:,13); 
% 
%    % GENERATOR PARAMETERS
%    refbus= find(mpc.gen(:,2)==3);
%    Pg= mpc.gen(:,2)
%    Qg= mpc.gen(:,3)
%    Pmax=mpc.gen(:,9);
%    Pmin=mpc.gen(:,10);
%    Qmax=mpc.gen(:,4);
%    Qmin=mpc.gen(:,5);
%    
%    % BRANCH PARAMETERS  
%    flow_lim=mpc.branch(:,6);
%    
%    % GENERATOR COST PARAMETERS
%    c_startup=mpc.gencost(:,2);
%    c_shutdown=mpc.gencost(:,3);
%    ncost= max(mpc.gencost(:,4));
%    % THE LINES UNDER ARE VALID IF MODEL IS 2 POLYNOMIAL
%    costmodel=mpc.gencost(:,1);
%      Ngen=length(mpc.gen(:,1));
%    costgen=zeros(Ngen,ncost);
%    
%    
%    for i=1:Ngen
% %         if (mpc.gencost(i,1)==2)
%             for j=1:ncost
%                 costgen(i,j)=mpc.gencost(i,4+j);
%             end
%                  if ncost== 3
%                     c_A(i)  =costgen(i,1);
%                     c_B(i)  =costgen(i,2);
%                     c_C(i)  =costgen(i,3);
%                  elseif ncost==2  
%                     c_A(i)  =0;
%                     c_B(i)  =costgen(i,1);
%                     c_C(i)  =costgen(i,2);
%                  end
%    end
%                 
%      onoff= zeros(Ngen,1);
% %      alpha= [];
% %      beta = [];
%         alpha= zeros(Ngen,1);
%         beta= zeros(Ngen,1);
%      for i=1:Ngen
%          if Pg(i)>0 | Qg(i)~= 0
%             onoff(i,1)=1;
%          else
%              onoff(i,1)=0;
%          end
%      end
%      onoff
%      
%   mpc
%  disp (['The generator costs follow the model [row= gen]']);
%  costmodel
%  disp(['with number of coefficients']);
%  mpc.gencost(:,4)
%  disp(['The cost matrix (row=gen, column= cost coefficients) is']);
%  costgen
%  
%  return

Reply via email to