Normalna distribucija

?NormalDistribution

Random[NormalDistribution[0,1]]

?Fit

?Random

(* LPNK (Mathematica) *)
xd={-4,-2,2,4}; yd={8,6,3,5}; m=Length[xd];
f[x_]:=2x-1
(* m=20; xd=Table[i,{i,m}]; yd=Table[f[xd[[i]]]+Random[NormalDistribution[0,2]],{i,m}];*)
data=Table[{xd[[i]],yd[[i]]},{i,m}];
sldat=ListPlot[data,PlotStyle->AbsolutePointSize[4]];
(* Print["podaci: ",TableForm[data]] *)
model=Fit[data,{1,xx},xx];
f[x_]:=model[[1]]+model[[2]][[1]] x
slf=Plot[f[x],{x,xd[[1]],xd[[m]]}];
Show[slf,sldat]
f[x]

NPNK - Trazenje polozaja broda

m=4;x={13,-2,-7,15}; y={7,14,-7,-11}; alpha={50,-80,10,-30}; alpha=N[Pi alpha/180];

F1[xx_,yy_]:=.5 Sum[(ArcTan[(yy-y[[i]])/(xx-x[[i]])]-alpha[[i]])^2,{i,m}];
F2[xx_,yy_]:=.5 Sum[((yy-y[[i]])/(xx-x[[i]])-Tan[alpha[[i]]])^2,{i,m}];
F3[xx_,yy_]:=.5 Sum[((yy-y[[i]])-(xx-x[[i]]) Tan[alpha[[i]]])^2,{i,m}]
min1=FindMinimum[F1[xx,yy],{xx,2},{yy,-3}];
min2=FindMinimum[F2[xx,yy],{xx,2},{yy,-3}];
min3=FindMinimum[F3[xx,yy],{xx,2},{yy,-3}];
Print["F1: ",min1]; Print["F2: ",min2]; Print["F3: ",min3];

sl1=ContourPlot[F1[xx,yy],{xx,0,5},{yy,-10,0},ContourShading->False,PlotLabel->"a)"];
sl2=ContourPlot[F2[xx,yy],{xx,0,5},{yy,-10,0},ContourShading->False,PlotLabel->"b)"];
sl3=ContourPlot[F3[xx,yy],{xx,0,5},{yy,-10,0},ContourShading->False,PlotLabel->"c)"];
Show[GraphicsArray[{sl1,sl2,sl3}]]

Primjena modula NMinimize

NMinimize[F1[xx,yy],{xx,yy}]