Linearna regresija

?NormalDistribution

Simuliranje podataka

f[x_]:=2x+1
m=6; SeedRandom[13]
x=Table[i/2.,{i,m}];
error=RandomReal[NormalDistribution[0,1],m];
y=f[x]+error;
tab=Table[{x[[i]],f[x[[i]]],error[[i]],y[[i]]},{i,m}];
Transpose[tab]//TableForm
pod=Table[{x[[i]],y[[i]]},{i,m}];
slpod=ListPlot[pod,PlotRange->{0,8},PlotStyle->{AbsolutePointSize[5]}];
F[al_,be_]:=Total[(y-al x- be )^2]
min=NMinimize[F[al,be],{al,be}]
Print["Var=",var=min[[1]]/m,"   sd=",Sqrt[var] ]
al1=al/.min[[2]];be1=be/.min[[2]];
slfp=Plot[al1 x+be1 ,{x,x[[1]]-1,x[[m]]+1}];
Show[slfp,slpod]

?Fit

Fit[pod,{1,u},u]

Zadatak

Graficki prikazite vektor pogresaka error, pri cemu varirajte m i SeedRandom