Add Tools->Basic Fitting->...Weighted least squares

jmgoldba on 19 Jun 2024
Latest activity Reply by Tim on 21 Jun 2024

An option for 10th degree polynomials but no weighted linear least squares. Seriously? Jesse
Tim
Tim on 21 Jun 2024
It's only a few lines of code to make your own.
PolyOrder = 10; % Order of polynomial
N = 50; % Length of signal
B = rand(N, 1); % Signal
B(floor([.1, .7]*N)) = [-1, 1]*10; % Outliers
w = ones(N, 1); % Weights
w(floor([.1, .7]*N)) = 0;
W = diag(w);
A = linspace(-1, 1, N)'.^(0:PolyOrder); % Dictionary
xw = (A'*W*A)\(A'*W*B); % WLS fit
x = (A'*A)\(A'*B); % LS fit
plot(B, 'k');
hold on;
plot(A*x, 'b');
plot(A*xw, 'm');
hold off;
legend('Data', 'LS', 'WLS');

Tags

No tags entered yet.