Hi Yang, Unfortunately, I don’t have time at the moment to look at your code, but what you describe should work, if you are able to provide the right functions and derivatives (not sure how well the methods that don’t require derivatives work).
I actually implemented a wrapper around runopf() to use it to solve the power flow problem. So if you’re using FMINCON as the OPF solver it should be something similar to your second approach, though implemented differently (probably more variables and constraints). See the attached file called runpfbyopf.m. Ray On Mar 6, 2021, at 10:45 PM, yangyang <980182...@qq.com<mailto:980182...@qq.com>> wrote: Dear Ray, Recently I am doing research on implementing of power flow (note: NOT OPTIMAL POWER FLOW) using matlab function fmincon(). I have two kinds of implementation: One is to take the normF in newtonpf() as the objective for fmincon(), since the process of newtonpf() is just the process of minimizing normF until it is smaller than tolerance. The second implementation is to use the equality constraints of power balance, that is, F = V .* conj(Ybus * V) - Sbus; where V is the complex voltage vector and Sbus is generated using makeSbus(), and then the equaltiy and inequaltiy constranits are: ceq = [real(F(pv; pq)); imag(F(pq))]; cineq = []; There are no inequality constranits for the 9th argin of fmincon (nnlcon) since the power flow equations dont need inequaltiy constraints. For the objective of fmincon(), a useless function handle that doesnt change with input at all is used, since the equality constraints are used, no objective is needed and nothing is optimized, so the only need is to keep the constraints. The objective can be like: @(x) sum(0 * x) Theretically, I think this is a feasible way, but for the 1st implementaion, the fmincon() always fail to find a good normF, and such ouptput will be reported: Solver stopped prematurely. fmincon stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 3.000000e+03. and the fbest is always around 0.1 to 0.7, which is much worse than the tolerance (around 1e-5 to 1e-8). For the second implementation, the same report will appear, and the results are also not very good. I am wondering if there are suitable ways to set up input arguments for the fmincon() function to calculate a accurate solution like runpf()? My codes are as attached. Function runpf_fmincon can be compatible with any mpc struct. The first implementation is fminconpf and the 2nd fminconpf2; change the function name in line 177 in runpf_fmincon from fminconpf to fminconpf2, to test the 2nd implementation. Thank you for your patience and time. ________________________________ Best Regards, Yang Yang <runpf_fmincon.m><fminconpf2.m><fminconpf.m>
runpfbyopf.m
Description: runpfbyopf.m