(* ::Package:: *) BeginPackage["extrapolation`"] simul::usage = "simul[a0,b0,x,\[Sigma]] returns the object from the fit of a,b of expression a+bx to a simulated dataset with y=a0+b0+error, where error is drawn accordign the normal distribution with standard deviation \[Sigma]. x is the independent data vector, hence it gives the number of data points to use." value::usage = "value[fit,x] returns a list with the interpolated value using the fitted parameters and the fit chi-square" \[Sigma]value::usage = "\[Sigma]value[fit,x] gives the calculated standard deviation in the value interpolated in point x." Begin["Private`"] simul[a0_,b0_,x_,\[Sigma]_]:=Module[{dado},\[Sigma]i=\[Sigma]; dado=Table[{x[[i]],RandomVariate[ NormalDistribution[a0+b0 x[[i]],\[Sigma]] ]},{i,Length[x]}]; LinearModelFit[dado,{z},z,Weights->1/ConstantArray[\[Sigma]^2,Length[x] ],VarianceEstimatorFunction->(1&) ] ] value[fit_,x_]:=Module[{v,y},v={1,x};{fit[x],Total[(fit["FitResiduals"]/\[Sigma]i)^2]} ] \[Sigma]value[fit_,x_]:=Module[{v,y},v={1,x};Sqrt[ v.fit["CovarianceMatrix"].v ] ] End[] EndPackage[]