[regression] first exercise

This commit is contained in:
2020-12-20 23:16:56 +01:00
parent c2e4d4e40c
commit 4b18c855b9
15 changed files with 444 additions and 75 deletions

View File

@@ -0,0 +1,4 @@
function funcPlotter(func)
x = 0:0.1:10.0;
plot(x,func(x));
end

View File

@@ -0,0 +1,2 @@
funcPlotter(@sin);

View File

@@ -0,0 +1,13 @@
meansquarederrorline; % generate data
p0 = [2.0, 1.0];
pest = lsqcurvefit(@powerLaw, p0, x, y)
hold on;
% generate x-values for plottig the fit:
xx = min(x):0.01:max(x);
yy = powerLaw(xx, pest);
plot(xx, yy); % plot fit
plot(x, y, 'o'); % plot original data
xlabel('Size [m]');
ylabel('Weight [kg]');
legend('fit', 'data', 'location', 'northwest');

View File

@@ -0,0 +1,9 @@
function y = powerLaw(x, p)
% Power law function y = c*x^alpha.
%
% Arguments: x, vector of the x-data values.
% p, vector with parameter values c and alpha
%
% Returns: y, vector of the computed y-data values.
y = p(1)*x.^p(2);
end