Berechnung einer Regressionsgeraden

Bitte schalten Sie Java ein, um eine Cinderella-Konstruktion zu sehen.

Skriptcode in Zeichnen:


//Least-square line
pts=allpoints();
m=apply(pts,(1,#.x));
y=apply(pts,#.y);
ma=transpose(m)*m;
mb=transpose(m)*y;
mainv=inverse(ma);
v=mainv*mb;
f(x):=v_2*x+v_1;
plot(f(x));


//Draw the squares

sq(x,y1,y2):=(
   d=y2-y1;
   p=((x,y1),(x,y2),(x+d,y2),(x+d,y1),(x,y1));
   drawpoly(p,color->(1,0.5,0.5),alpha->0.4);
   connect(p,color->(.8,0,0));
);

forall(pts,sq(#.x,#.y,(f(#.x))));

Created with Cinderella