File Exchange

image thumbnail

Power System State Estimation using WLS

version (6.74 KB) by Praviraj PG
Power System State Estimation using Weighted Least Square Method


Updated 21 Feb 2009

View License

Power System State Estimation using Weighted Least Square Method. Measurements are voltage magnitude, power injection and power flows.

Cite As

Praviraj PG (2020). Power System State Estimation using WLS (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (39)

Nice coding. I noticed that for the power flow calculations it is being considered the G and B (capital) as the real and imaginary parts of the Y matrix. The correct formula uses the g and b, which is the 1/r and 1/x without the minus signals when the element is off the diagonal. Thanks a lot for your code, it helped me a lot.

The code is very useful! But there might be a small mistake!
In the function "WLS_SE", the 76th line, the condition "n==k" may be changed to "n==zdata(k,4)". The current code works well for the given zdatas, but if the measurement of voltage magnitudes are different, there might be mistakes for the current condition "n==k".

A perfect code. Thanks so much.

The code is running for almost half an hour now. Does it take that long? (I am using a very simple 4 bus system)

Eric Wu

Xiaoli LIU

Thanks a lot.


can someone tell me how to get the z-data from zdatas (num) file


useful reference value but slightly error exits.
H12 should be "n == fbus(k)".
It should be aware the measurement function and the derivative of power flow at transformer branch are different from transmission lines, the tap should be considered.
what Hasnae Bilil said is wrong, the code is right here.

pagna kean

My code show that "Undefined function or variable 'wls_function'. " how to get wls_function file?

Min Zhou

thank you, it's helpful.

Very good code. But for the 30 bus case the output is showing for bus 1 -27, bus 28,29 and 30 is missing. What can be the reason?

I apologize, there is no mistake in the file wls.m, as mentioned on my previous message. Congrats

Thank you, the code is very good. However, I think the code has a littre mistake in file wls.m, line 60, defining the function of the active power flow as
"h4(i) = -V(m)^2*G(m,n) - V(m)*V(n)*(-G(m,n)*cos(del(m)-del(n)) - B(m,n)*sin(del(m)-del(n)));"
The minus before V(m) needs to be removed. This the correct function,
"h4(i) = V(m)^2*G(m,n) - V(m)*V(n)*(-G(m,n)*cos(del(m)-del(n)) - B(m,n)*sin(del(m)-del(n)));"

Preeti Jain

thanku sir

hi i want to use this program with more grip I do?


Does someone maybe has an example for WLS Topology Error Detection And Identification???
It would mean me a lot...
Thank you.

Fiaz Ahmad

What is the problem Ammara

Ammara Gul

Is there anyone to help me. I could not run this file, I dont know why..


Hello all
Anybody know how to run decouple state estimation or its code? in matlab


thanks for your help


Thank you, very useful and perfectly developed

Very nice, congrats and many thanks!


Great work, but i need some info on how to incorporate PMU measurements.


Thanks for Benevolence


thanks alot


Apologies for above comment but still the output for 14 bus system gives only 13 results while that for 30 bus system only 27 results are being obtained


Dear Sir, For 30 Bus System there is an error [In wls at 230
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN. ] Also there is no measurement file for 57 bus system

the calculation of H12(element of Jacobian Matrix) is incorrect.

It was useful.
You are legend :)

It is very good, but i'm very happy to get the WLS method with Hypothesis Testing instead of Normalized Residuals, for my final year project.
pleas help me, I'll so thankful.


Hi Pravi, coded neat and clean. Just wondering how come ur ans doesnt match with LF ones? thx


someone has a version of the state estimator in C language ????

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux