This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/regression/code/plotgradientdescentpower.m

31 lines
831 B
Matlab

meansquarederrorline; % generate data
p0 = [2.0, 1.0];
eps = 0.00001;
thresh = 1.0;
[pest, ps, mses] = gradientDescent(x, y, @powerLaw, p0, eps, thresh);
pest
subplot(2, 2, 1); % top left panel
hold on;
plot(ps(1,:), ps(2,:), '.');
plot(ps(1,end), ps(2,end), 'og');
plot(c, 3.0, 'or'); % dot indicating true parameter values
hold off;
xlabel('Iteration');
ylabel('C');
subplot(2, 2, 3); % bottom left panel
plot(mses, '-o');
xlabel('Iteration steps');
ylabel('MSE');
subplot(1, 2, 2); % right panel
hold on;
% generate x-values for plottig the fit:
xx = min(x):0.01:max(x);
yy = powerLaw(xx, pest);
plot(xx, yy);
plot(x, y, 'o'); % plot original data
xlabel('Size [m]');
ylabel('Weight [kg]');
legend('fit', 'data', 'location', 'northwest');