1. A method for injecting power into or extracting power out of a power network at a point of common coupling (PCC) having one or more wires, comprising: obtaining Thévenin parameters in the form of at least a Thévenin voltage and a Thévenin resistance of an equivalent Thévenin circuit with respect to each wire of the PCC; calculating a total Thévenin power for all the wires based on a specific amount of power at the PCC and the obtained Thévenin parameters; calculating an optimal current to be injected into or extracted from the PCC so as to inject or extract a specific amount of power, wherein the calculation is based on the total Thévenin power and the Thévenin parameters including: changing Thévenin voltages for wires at a resistance weighted null reference point to a weighted Thévenin equivalent voltage vector dependent on Thévenin equivalent resistances; calculating an optimal Thévenin total wire power at the equivalent Thévenin voltage points; calculating a constant kA with the calculated Thévenin total wire power divided by the norm squared of the weighted Thévenin equivalent voltage vector; and calculating a weighted current vector by multiplying the constant kA by the weighted Thévenin voltage vector; and controlling an injection or extraction of current at the PCC in accordance with the optimal current.