0% found this document useful (0 votes)
54 views2 pages

State Estimation

This document contains MATLAB code that performs a weighted least squares regression analysis. It defines vectors z, w, and h, calculates the regression X and residual e, and computes the weighted sum of squares C. It then compares C to critical values from a table to determine if the data is accepted or if one data point should be removed as bad data.

Uploaded by

Albert Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

State Estimation

This document contains MATLAB code that performs a weighted least squares regression analysis. It defines vectors z, w, and h, calculates the regression X and residual e, and computes the weighted sum of squares C. It then compares C to critical values from a table to determine if the data is accepted or if one data point should be removed as bad data.

Uploaded by

Albert Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

clear all;

clc;
z=[9.01
3.02
6.98
4.40];
disp('z=');
disp(z);
w=[100 0 0 0
0 100 0 0
0 0 50 0
0 0 0 50];
disp('w=');
disp(w);
h=[0.625 -0.125
-0.125 0.625
0.375 0.125
0.125 0.375];
disp('h=');
disp(h);
e=1;
while(e>0.001)
g=h'*w*h;
g1=h'*w*z;
X=(inv(g))*g1;
Z=h*X;
e=z-Z;
disp('e=');
disp(e);
n=length(z);
m=length(X);
C=0;
for i=1:n
f=e(i)*e(i)*w(i,i);
C=C+f;
end
disp('f=');
disp(C);
k=n-m;
c=[ 3.84 5.02 6.64 7.88;
5.99 7.38 9.21 10.6
7.82 9.35 11.35 12.84];
disp(c)
for i=k
for j=3;
if C<c(k,3)
disp('accepted data')
elseif C>c(k,3)
disp('unaccepted data')
%identify bad data
h(4,:)=[];
z(4,:)=[];
w(4,:)=[];
w(:,4)=[];
end
end
end
end
% g=h'*w*h;
% g1=h'*w*z;
% X=inv(g)*g1;
% Z=h*X;
% e=z-Z;
% disp('e=');
% disp(e);
% C=0;
% for i=1:n
% fh(i)=((e(i)^2)*w(i,i));
% C=C+fh(i);
% end
% disp('f=');
% disp(fh(i));

You might also like