22 lines
393 B
Matlab
22 lines
393 B
Matlab
clear
|
|
close all
|
|
load('lin_regression.mat')
|
|
|
|
pstart = [-2. 10.];
|
|
[params, errors] = descent(x, y, pstart);
|
|
|
|
figure()
|
|
subplot(2,1,1)
|
|
hold on
|
|
scatter(x, y, 'displayname', 'data')
|
|
xx = min(x):0.01:max(x);
|
|
fx = params(1)*xx + params(2);
|
|
plot(xx, fx, 'displayname', 'fit')
|
|
xlabel('Input')
|
|
ylabel('Output')
|
|
grid on
|
|
legend show
|
|
subplot(2,1,2)
|
|
plot(errors)
|
|
xlabel('optimization steps')
|
|
ylabel('error') |