[regression] first exercise
This commit is contained in:
4
regression/code/funcPlotter.m
Normal file
4
regression/code/funcPlotter.m
Normal file
@@ -0,0 +1,4 @@
|
||||
function funcPlotter(func)
|
||||
x = 0:0.1:10.0;
|
||||
plot(x,func(x));
|
||||
end
|
||||
2
regression/code/funcplotterexamples.m
Normal file
2
regression/code/funcplotterexamples.m
Normal file
@@ -0,0 +1,2 @@
|
||||
funcPlotter(@sin);
|
||||
|
||||
13
regression/code/plotlsqcurvefitpower.m
Normal file
13
regression/code/plotlsqcurvefitpower.m
Normal 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');
|
||||
9
regression/code/powerLaw.m
Normal file
9
regression/code/powerLaw.m
Normal 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
|
||||
Reference in New Issue
Block a user