# How to deal with optimal power flow problem in MATLAB?

I am writing an optimal power flow (OPF) program. OPF is an optimization problem in which some decision variables like Generation, Load dispatch are adjusted in power flow program so as to minimize the objective function (usually cost of generation).
I am using fmincon Matlab function to solve this problem. Like any optimization problem, OPF have some linear and nonlinear constraints. These constraints are added to the problem to guarantee the feasibility of the solution. I wrote these constraint in Matlab, but I am getting infeasible results which is due to constraints. The constraints of this problem are as follows:

In Here I have posted part of my code that I need to supply the constraints to fmincon. Please check if I wrote the constraints are correct .

Note:I used IEEE New England test system to run OPF on it. This test system contains, 39 Buses, 19 Loads,10 Generators, 46 Lines.

• It would be helpful if you added some more description of your power system, like no. of generators, no. of buses and their types, loads, etc. – Adeel May 7 '15 at 8:16
• Thanks for your point. The power system data is available in the posted file. I used IEEE New England test system to run OPF on it. This test system contains, 39 Buses, 19 Loads,10 Generators, 46 Lines. @AdeelSabir – Jamais avenir May 7 '15 at 8:23
• I personally have not used fmincon. But my suggestion is, if you can test a similar but smaller system, and then work your way up in steps. You can also remove some constraints, then sequentially add them, to single out the constraint that causes infeasibility. – Adeel May 7 '15 at 8:30
• Thanks for your comment. I already added the constraints sequentially and also solved them as a nonlinear system using fsolve to see if the problem is feasible. I think the constraints are feasible. But when I put it in optimization (fmincon) problem it doesn't give the optimal solution. I am now very doubtful if I wrote the constraints correctly in my codes. I also have the same problem in GAMS and that works fine. I checked my script with GAMS and I can't understand why mine doesn't work. @AdeelSabir – Jamais avenir May 7 '15 at 8:39
• I've had a similar experience using convex optimization. It sometimes depends on the solver too. A problem can be feasible under one solver and infeasible under another. The degree of feasibility also can differ with different solvers. If you are familiar with YALMIP you can choose from a variety of solvers to solve your problem. I personally found YALMIP to a be much more satisfying experience for convex optimization than MATLAB's default LMI toolbox. – Adeel May 7 '15 at 8:53