Bestimmen einer Ausgleichsgeraden
> restart; with(plots):
interface(displayprecision = 4):
fnt:= 'style = point,
symbol = cross,
symbolsize = 15,
size = [400,350],
axes = normal,
axesfont = [Courier, normal, 10],
labelfont = [Courier, normal, 12],
labels = [x, y]':
interface(displayprecision = 4):
fnt:= 'style = point,
symbol = cross,
symbolsize = 15,
size = [400,350],
axes = normal,
axesfont = [Courier, normal, 10],
labelfont = [Courier, normal, 12],
labels = [x, y]':
Messtabelle:
> M:= [[2.1, .425],
[2.2, .351],
[2.4, .281],
[2.6, .228],
[2.7, .137],
[2.8, .163],
[2.9, .084],
[3.0, .047],
[3.1, .013],
[3.3, -.048],
[3.5, -.099],
[3.7, -.142]]:
[2.4, .281],
[2.6, .228],
[2.7, .137],
[2.8, .163],
[2.9, .084],
[3.0, .047],
[3.1, .013],
[3.3, -.048],
[3.5, -.099],
[3.7, -.142]]:
> plot({seq(M[i], i = 1..nops(M))},
x = 2..4,
fnt);
x = 2..4,
fnt);
Die Funktionsgleichung der „besten Gerade“:
> f:= x -> m*x + b;
Die Summe der Gauß’schen Fehlerquadrate:
> S:= (m, b) -> sum((y[i] - f(x[i]))^2, i = 1..n);
S(m, b);
S ist in Abhängigkeit von m und b zu minimieren:
> gln:= {diff(S(m,b), m) = 0, diff(S(m,b), b) = 0}:
gln[1];
gln[2];
gln[2];
Die Lösungen der Gleichungen gln[1] und gln[2]:
> lgn:= solve(gln, {m, b}):
lgn[1];
lgn[1];
lgn[2];
> n:= nops(M);
for j to n do
x[j]:= M[j,1]:
y[j]:= M[j,2]:
od:
x[j]:= M[j,1]:
y[j]:= M[j,2]:
od:
> lgn: assign(lgn):
m:= evalf(m, 4);
b:= evalf(b, 4);
b:= evalf(b, 4);
> f(x):= m*x + b;
> Punkte:= plot({seq(M[i], i = 1..n)},
x = 2..4,
x = 2..4,
fnt):
Gerade:= plot ([f(x)], x = 2..4,
style = line,
color = blue):
display ([Punkte, Gerade]);
Gerade:= plot ([f(x)], x = 2..4,
style = line,
color = blue):
display ([Punkte, Gerade]);