summaryrefslogtreecommitdiff
path: root/display_data.m
blob: 4affa96b73c3a3b60554275f92f7a3b0862e09e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
for i = [30 45]
	p = dlmread(sprintf("products/p%03d", i), " ");

	day = p(:,1);
	quantity = p(:,4);

	middle = repmat(mean(p(:,4)), 42, 1);
	middle_20 = repmat(mean(p(1:20, 4)), 42, 1);

	[m, n] = regress(day, quantity);
	f = @(x) m .* x + n;

	[m, n] = regress(day(1:20), quantity(1:20));
	g = @(x) m .* x + n;

	figure
	plot(day, p(:,4),    "-;quantity;",
	     day, middle,    "-;Mittelwert;",
	     day, middle_20, "-;Mittelwert 1-20;",
	     day, f(day),    "-;Regression 1-42;",
	     day, g(day),    "-;Regression 1-20;")

endfor

function [m, n] = regress(x, y)
  mn = [ x ones(length(x), 1) ] \ y;
  m = mn(1);
  n = mn(2);
endfunction