
MATPOWER
A MATLAB Power System Simulation Package
by Ray D. Zimmerman, Carlos E. MurilloSánchez & Deqiang (David) Gan
MATPOWER is a package of MATLAB® Mfiles for solving power flow and optimal power flow problems. It is intended as a simulation tool for researchers and educators that is easy to use and modify. MATPOWER is designed to give the best performance possible while keeping the code simple to understand and modify. It was initially developed as part
of the PowerWeb project.
You will be asked to fill out a brief form the first time you download nonGPL software from this site.
See also Optional Packages below.
For full documentation, see the MATPOWER Users's Manual.

Terms of Use (MATPOWER 4 and later)
Please see the LICENSE file for
the details. But here is the summary ...
 Beginning with version 4, the code in MATPOWER is distributed under
the GNU General Public License (GPL) with an exception added to clarify
our intention to allow MATPOWER to interface with MATLAB® as
well as any other MATLAB code or MEXfiles a user may have installed, regardless of their licensing terms.
 MATPOWER is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
 While not required by the terms of the license, we do request that
publications derived from the use of MATPOWER explicitly acknowledge
that fact by citing [2].
[2] 
R. D. Zimmerman, C. E. MurilloSánchez, and R. J. Thomas, "MATPOWER: SteadyState Operations, Planning and Analysis Tools for Power Systems Research and Education," Power Systems, IEEE Transactions on, vol. 26, no. 1, pp. 1219, Feb. 2011. 
Note: Versions prior to MATPOWER 4 use a different license.


System Requirements
To use MATPOWER you will need:
Note: MATPOWER 4 required MATLAB 6.5, MATPOWER 3.2 required MATLAB 6, MATPOWER 3.0 required MATLAB 5 and MATPOWER 2.0 and earlier only required MATLAB 4. Some parts of MATPOWER may work on earlier versions of Octave, but it but has not been tested on versions prior to 3.4, and psse2mpc currently requires 3.8 or newer.
Installation
 Download MATPOWER. You should end up with a file named matpowerXXX.zip, where XXX depends on the version of MATPOWER.
 Unzip the downloaded file. Move the resulting matpowerXXX directory to the location of your choice. These files should not need to be modified, so it is recommended that they be kept separate from your own code. Let $MATPOWER denote the path to this directory.
 Add the following directories to your MATLAB path:
 $MATPOWER — core MATPOWER functions
 $MATPOWER/t — test scripts for MATPOWER
 At the MATLAB prompt, type 'test_matpower' (without the quotes) to run the test suite and verify that MATPOWER is properly installed and functioning.
Running MATPOWER
To run a simple Newton power flow on the 9bus system specified in the file case9.m, with the default algorithm options, at the MATLAB prompt, type:
runpf('case9')
To load the 30bus system data from case30.m, increase its real power
demand at bus 2 to 30 MW, then run an AC optimal power flow with
default options, type:
define_constants;
mpc = loadcase('case30');
mpc.bus(2, PD) = 30;
runopf(mpc);
By default, the results of the simulation are prettyprinted to the screen, but the solution can also be optionally returned in a results struct. The following example shows how simple it is, after running a DC OPF on the 118bus system in case118.m, to access the final objective function value, the real power output of generator 6 and the power flow in branch 51.
results = rundcopf('case118');
final_objective = results.f;
gen6_output = results.gen(6, PG);
branch51_flow = results.branch(51, PF);
For additional info, see the User's Manual and the online help documentation for the various MATPOWER functions. For example:
help runpf
help runopf
help mpoption
help caseformat
Below is a summary of the changes since version 4.1 of MATPOWER. See the CHANGES file in the docs directory for all the gory details.
New features:
 Continuation power flow with tangent predictor and Newton method corrector, based on code contributed by Shrirang Abhyankar and Alex Flueck.
 SDP_PF, a set of applications of a semidefinite programming relaxation of the power flow equations, contributed by Dan Molzahn (see extras/sdp_pf):
 Globally optimal AC OPF solver (under certain conditions).
 Functions to check sufficient conditions for:
 global optimality of OPF solution
 insolvability of power flow equations
 PSS/E RAW data conversion to MATPOWER case format (experimental) based on code contributed by Yujia Zhu.
 Brand new extensible MATPOWER options architecture based on options struct instead of options vector.
 Utility routines to check network connectivity and handle islands and isolated buses.
 New extension implementing DC OPF branch flow soft limits. See help toggle_softlims for details.
 New and updated support for 3rd party solvers:
 Numerous performance enhancements.
 New functions:
 runcpf() for continuation power flow.
 case_info() for summarizing system information, including network connectivity.
 extract_islands() to extract a network island into a separate MATPOWER case.
 find_islands() to detect network islands.
 @opt_model/describe_idx() to identify variable, constraint or cost row indices to aid in debugging.
 margcost() for computing the marginal cost of generation.
 psse2mpc() to convert PSS/E RAW date into MATPOWER case format.
 get_losses() to compute branch series losses and reactive charging injections and derivatives as functions of bus voltages.
 New experimental functions in extras/misc for computing loss factors, checking feasibility of solutions, converting losses to negative bus injections and modifying an OPF problem to make it feasible.
 Added case5.m, a 5bus, 5generator example case from Rui Bo.
 New options:
 scale_load() can scale corresponding gencost for dispatchable loads.
 makeJac() can return full Jacobian instead of reduced version used in Newton power flow updates.
 modcost() can accept a vector of shift/scale factors.
 total_load() can return actual or nominal values for dispatchable loads.
 runpf(), runopf(), etc. can send prettyprinted output to file without also sending it to the screen.
 out.suppress_detail option suppresses all output except system summary (on by default for large cases).
 opf.init_from_mpc() option forces some solvers to use usersupplied starting point.
 MIPS 1.1 includes many new usersettable options.
 Reimplementated @opf_model class as subclass of the new @opt_model class, which supports indexed named sets of variables, constraints and costs.
 Many new tests in test suite.
Bugs fixed:
 Running a power flow for a case with DC lines but no gencost no longer causes an error.
 Fixed a bug in runpf() where it was using the wrong initial voltage magnitude for generator buses marked as PQ buses. Power flow of solved case was not converging in zero iterations as expected.
 Fixed fatal bug in MIPS for unconstrained, scalar problems. Thanks to Han Na Gwon.
 Fixed a bug in int2ext() where converting a case to internal ordering before calling runpf() or runopf() could result in a fatal error due to mismatched number of columns in internal and external versions of data matrices. Thanks to Nasiruzzaman and Shiyang Li for reporting and detailing the issue.
 DC OPF now correctly sets voltage magnitudes to 1 p.u. in results.
 Fixed a bug in MIPS where a nearsingular matrix could produce an extremely large Newton step, resulting in incorrectly satisfying the relative feasibility criterion for successful termination.
 Improved the starting point created for Ipopt, Knitro and MIPS for variables that are only bounded on one side.
 Fixed bug in savecase() where the function name mistakenly included the path when the FNAME input included a path.
 Fixed bugs in runpf() related to enforcing generator reactive power limits when all generators violate limits or when the slack bus is converted to PQ.
 Fixed crash when using Knitro to solve cases with all lines unconstrained.
 Fixed memory issue resulting from nested om fields when repeatedly running an OPF using the results of a previous OPF as input. Thanks to Carlos MurilloSanchez.
 Fixed fatal error when uopf() shuts down all gens attempting to satisfy Pmin limits.
 Reactive power output of multiple generators at a PQ bus no longer get reallocated when running a power flow.
 Fixed a bug in savecase() where a gencost matrix with extra columns of zeros resulted in a corrupted MATPOWER case file.
 Fixed bug in runpf() that caused a crash for cases with pf.enforce_q_lims turned on and exactly two Q limit violations, one Qmax and one Qmin. Thanks to Jose Luis Marin.
INCOMPATIBLE CHANGES:
 Optional packages TSPOPF and MINOPF must be updated to latest versions.
 Renamed cdf2matp() to cdf2mpc() and updated the interface to be consistent with psse2mpc().
 Removed ot_opts field, replaced with linprog_opts and quadprog_opts fields in the opt argument to qps_matpower() and qps_ot().
 The name of the mips() option used to specify the maximum number of stepsize reductions with step_control on was changed from max_red to sc.red_it for consistency with other MATPOWER options.
 Removed max_it option from qps_matpower() (and friends) args. Use algorithm specific options to control iteration limits.
 Changed behavior of branch angle difference limits so that 0 is interpreted as unbounded only if both ANGMIN and ANGMAX are zero.
 In results struct returned by an OPF, the value of results.raw.output.alg is now a string, not an oldstyle numeric alg code.
 Removed:
 Support for Matlab 6.x.
 Support for constr() and successive LPbased OPF solvers.
 Support for Gurobi 4.x/gurobi_mex() interface.
 extras/cpf, replaced by runcpf().
 extras/psse2matpower, replaced by psse2mpc().
There are three primary sources of documentation for MATPOWER.
The User's Manual is included in the distribution (docs/manual.pdf) or it can be downloaded separately from the link above. Previous versions are available here.
Each Mfile has its own documentation which can be accessed by typing at the MATLAB prompt:
help <name of Mfile>
Documentation for the case data file format can be found by typing:
help caseformat
If something is still unclear after checking the manual and the
help, the source code is the documentation. ;)
There are also two MATPOWER Technical Notes that may be of interest:
[1] 
R. D. Zimmerman, C. E. MurilloSánchez, and R. J. Thomas, "MATPOWER's Extensible Optimal Power Flow Architecture," Power and Energy Society General Meeting, 2009 IEEE, pp. 17, July 2630 2009.
(Digital Object Identifier: 10.1109/PES.2009.5275967)
Presentation: download slides 
[2] 
R. D. Zimmerman, C. E. MurilloSánchez, and R. J. Thomas, "MATPOWER SteadyState Operations, Planning and Analysis Tools for Power Systems Research and Education," Power Systems, IEEE Transactions on, vol. 26, no. 1, pp. 1219, Feb. 2011.
(Digital Object Identifier: 10.1109/TPWRS.2010.2051168) 
There are a number of optional packages that MATPOWER can take advantage of to provide additional options for OPF solvers. Each is distributed under its own license and must be obtained separately. Please see the individual Terms of Use for details.
BPMPD_MEX 
MEXfile version of the high performance BPMPD interior point LP and QP solver. Speeds up DC and LPbased OPF solvers, and improves robustness of MINOPF. 
CPLEX 
Includes highperformance, largescale LP and QP solvers that MATPOWER can use for the DC OPF. Requires the Matlab interface to CPLEX, available from http://www.ibm.com/software/integration/optimization/cplexoptimizer/. 
GLPK 
GNU Linear Programming Kit includes largescale LP solvers that MATPOWER can use for the DC OPF. Included with Octave. 
GUROBI 
Includes highperformance, largescale LP and QP solvers that MATPOWER can use for the DC OPF. Requires the Gurobi MEX Matlab interface. 
IPOPT 
An interior point optimizer for large scale nonlinear optimization that MATPOWER can use for both AC and DC OPF problems. Requires the Matlab MEX interface for IPOPT, available from https://projects.coinor.org/Ipopt/. 
KNITRO 
A general purpose optimization solver specializing in nonlinear problems that MATPOWER can use for AC OPFs. Requires the Knitro libraries, available from http://www.ziena.com/ and the Optimization Toolbox from The MathWorks. 
MINOPF 
A MINOSbased AC OPF solver implemented as a Fortran MEX file. 
MOSEK 
Includes highperformance, largescale LP and QP solvers that MATPOWER can use for the DC OPF. Requires the Matlab interface to MOSEK, available from http://www.mosek.com/. 
TSPOPF 
A package of three AC OPF solvers implemented as C MEX files. Suitable for large scale problems. 
An email list MATPOWERL@cornell.edu has been set up
to facilitate discussion of MATPOWER. Only list subscribers are permitted to post to the list.
Feel free to use this list to discuss anything related to MATPOWER, to ask questions about MATPOWER, or to provide feedback to the developers of MATPOWER, such as bug reports, patches or ideas for improvements (though we make no guarantees about if/when they might be included).
Also, if you have any of your own MATLAB power systems code that you would like to contribute, feel free to contact us via this list about making it available on the MATPOWER web site.
Joining the list
To join the MATPOWER mailing list, send a plaintext email to MATPOWERLrequest@cornell.edu with the following line in the body of the message.
join
You must send the request from the email address where you want to receive the list's messages. And be sure it is a plain text email, that is, with no formatting, font styles or HTML code.
Sending mail to the list
To send an email to all of the subscribers of the MATPOWER mailing list, simply address your email to MATPOWERL@cornell.edu. Only subscribers are permitted to send email to the list.
Leaving the list
You can unsubscribe from the list at any time by sending an email to MATPOWERLrequest@cornell.edu with the following line in the body of the message.
leave
List Archives
There is an archive of the MATPOWER email list hosted by The Mail Archive.
http://www.mailarchive.com/matpowerl@cornell.edu/
It can be searched or browsed by thread or by date.
Note: There have been two URLs published for these archives, so you may find broken links out there pointing to (1), but (2) is the only one that works currently, so just edit the links accordingly.
(1) http://www.mailarchive.com/matpowerl@list.cornell.edu/
(2) http://www.mailarchive.com/matpowerl@cornell.edu/
Guidelines for posting
If you are going to ask a question on this list, please be sure to give enough information that someone has a chance of giving a helpful response. Be sure to start with ...
 a clear and complete description of what you are trying to accomplish
... and if you have attempted a solution unsuccessfully ...
 a clear and complete description of what you have already attempted (including a code snippet if possible so we have details)
 a clear and complete description of the result you expected vs. the result you got (if you got an error, include the full error message)
If MATPOWER itself is not working as you think it should, include ...
 output of mpver on your system
 operating system version
Including this kind of information in your request will make this forum more useful to everyone by avoiding the added noise of multiple emails back and forth in an attempt to understand the question.
To be notified when new versions of MATPOWER become available,
sign up
for the MATPOWERANNOUNCEL mailing list by sending an email, from the address where you would like receive the announcements, to:
MATPOWERANNOUNCELrequest@cornell.edu
Leave the subject line blank. The body of the message should be the single word:
join
You can unsubscribe from the announcement list at any time by sending an email to MATPOWERANNOUNCELrequest@cornell.edu with the following line in the body of the message.
leave
There is also an archive of the announcement list hosted by The Mail Archive.
http://www.mailarchive.com/matpowerannouncel@cornell.edu/
 1. How can I use MATPOWER's OPF to minimize transmission losses?
 Assign positive, constant, equal costs to all generators and use the standard OPF. Since generation must equal demand plus losses, if demand is constant, loss is minimized by minimizing overall generation. With equal costs on all generators, MATPOWER's default objective of minimizing total cost is equivalent to minimizing total generation, which is in turn equivalent to minimizing transmission losses.
 2. Would you please show me how to use MATPOWER to solve [my homework problem]?
 If you're thinking of posting a question of that nature to MATPOWERL, please don't ... the answer is "No, we won't". We simply do not have the time to understand every type of problem we are asked about and respond with example code to show you how MATPOWER can be used to solve it. MATPOWER solves power flow and optimal power flow problems and has a number of other related capabilities. You need to determine whether those capabilities are applicable to your problem.
If you have checked the User's Manual and the mailing list archives and still have questions about MATPOWER's specific capabilities, we are happy to clarify. And if you have specific questions, comments, or suggestions related to using MATPOWER, those are also welcome. Just please don't ask us to do your homework for you.
 3. Am I required by the license to cite MATPOWER in publications based on MATPOWER or derived works?
 No, but it's still the right thing to do. Please cite the following in your publications that rely on MATPOWER:

R. D. Zimmerman, C. E. MurilloSánchez, and R. J. Thomas, "MATPOWER: SteadyState Operations, Planning and Analysis Tools for Power Systems Research and Education," Power Systems, IEEE Transactions on, vol. 26, no. 1, pp. 1219, Feb. 2011. (Digital Object Identifier: 10.1109/TPWRS.2010.2051168) 
 4. Can I use MATPOWER with GPLincompatible Mfiles and MEXfiles?
 I am not a lawyer. However, a GPL v3 section 7 "additional
permission" exception is included with the intent to explicitly
permit interfacing of MATPOWER with any Mfiles and MEXfiles,
regardless of licensing, such as MINOPF, BPMPD_MEX and Matlab's
Optimization Toolbox.
 5. Why does MATPOWER power flow not converge?
 While there are many reasons for the nonconvergence of a power flow solution, the following hints/tips may be useful for debugging the problem.
 Check that the data in the case file is consistent with the MATPOWER case data format.
 Check that all transmission line data is in per unit. MATPOWER requires the branch data to be entered in per unit.
 Check whether there are isolated buses in the case file that are not
marked with BUS_TYPE = NONE (4) or if there are islands without generation. This information can be obtained using the routine case_info().
 By default, MATPOWER's AC power flow uses a Newton's method to solve the nonlinear power flow equations and, unfortunately, the Newton's method is sensitive to the initial guess given. There is no way to choose an initial guess that always guarantees convergence. The following experiments may be useful in such a case:
 Change the starting point (voltage angles and magnitudes) and see if the power flow converges.
 Run a fast decoupled power flow (see help mpoption for details).
 Run an OPF with active generation fixed (costcoefficients should not matter), voltage limits relaxed except at generator buses, and reactive generation and branch flow limits relaxed.
 AC power flow does not converge if the system load exceeds the steadystate loading limit. To check if this is the case, run a continuation power flow that gradually increases the loading/generation.
define_constants;
mpcbase = loadcase('casefile');
mpc.bus(:, PD) = 0;
mpc.bus(:, QD) = 0;
mpc.gen(:, PG) = 0;
mpctarget = loadcase('casefile');
results = runcpf(mpcbase, mpctarget);
results.cpf.max_lam
If the resulting value of results.cpf.max_lam (the scaling factor associated with the maximum loading the system can handle) is less than 1, it indicates that the load for the case exceeds the steadystate loading limit, and loads must be scaled down at least by a factor of results.cpf.max_lam to get a convergent power flow solution.
