Back to Problems

## Mean and Standard deviation

`H.Tahsiri`

### Method 1 (using equations)

```x={50.36,50.35,50.41,50.37,50.36,50.32,50.39,50.38,50.36,50.38}

{50.36, 50.35, 50.41, 50.37, 50.36, 50.32, 50.39, 50.38, 50.36, 50.38}```

```n=Length[x]

10

meanx=1/n Sum[x[[i]],{i,1,n}]

50.368```

```sigmax=Sqrt[1/(n-1) Sum[(x[[i]]-meanx)^2,{i,1,n}]]

0.024404```

```sdomx=sigmax/Sqrt[n]//N

0.00771722```

### Method 2 (using Mathematica command)

`<<DescriptiveStatistics.m`

`Clear[x,n,meanx,sigmax,sdomx]`

```x={50.36,50.35,50.41,50.37,50.36,50.32,50.39,50.38,50.36,50.38}

{50.36, 50.35, 50.41, 50.37, 50.36, 50.32, 50.39, 50.38, 50.36, 50.38}```

```n=Length[x]

10```

```meanx=Mean[x]

50.368```

```sigmax=StandardDeviation[x]

0.024404```

```sdomx=sigmax/Sqrt[n]//N

0.00771722```

```StandardErrorOfSampleMean[x](*this uses Sqrt[n-1]*)

0.00813467```

## Linear Least Squares Fits

### Method 1 (using equations)

`Clear[x,y,n]`

```x={1,2,3,4,5}

{1, 2, 3, 4, 5}```

```y={7.57,11.97,16.58,21,25.49}

{7.57, 11.97, 16.58, 21, 25.49}```

```n=Length[x Or y]

5```

`s1= Sum[x[[i]] y[[i]],{i,n}];`

`s2=Sum[x[[i]],{i,n}];`

`s3=Sum[y[[i]],{i,n}];`

`s4= Sum[x[[i]]^2,{i,n}];`

`s5=(Sum[x[[i]],{i,n}])^2;`

`s7=(Sum[x[[i]]^2,{i,n}]);`

`s8=(Sum[y[[i]]^2,{i,n}]);`

```corrcoeff=(n s1-s2*s3)/((Sqrt[n s4-s5])*(Sqrt[n s8-s9]))//N

0.99998```

```m=(n*s1-s2*s3)/(n*s4-s5)

4.487```

```b=(s3*s4-s1*s2)/(n*s4-s5)

3.061```

```Y=m X + b

3.061 + 4.487 X```

`Clear[t,v0,v]`

`v[t_]:=3.061 + 4.487 t`

`fitplot=Plot[v[t],{t,0,5},DisplayFunction->Identity];`

```data={{1,7.57},{2,11.97},{3,16.58},{4,21},{5,25.49}}

{{1, 7.57}, {2, 11.97}, {3, 16.58}, {4, 21}, {5, 25.49}}```

```dataplot=ListPlot[data,PlotRange->{{0,5},{0,30}},
PlotStyle->PointSize[0.02],DisplayFunction->Identity];
together=Show[{dataplot,fitplot},
DisplayFunction->\$DisplayFunction];```

### Method 2 (using Mathematica command)

```data={{1, 7.57}, {2, 11.97}, {3, 16.58}, {4, 21}, {5, 25.49}}
{{1, 7.57}, {2, 11.97}, {3, 16.58}, {4, 21}, {5, 25.49}}```

```squarefit=Fit[data,{1,t},t]

3.061 + 4.487 t```

```plotsquarefit=Plot[squarefit,{t,0,5},DisplayFunction->Identity];
dataplot=ListPlot[data,PlotStyle->PointSize[0.02],
DisplayFunction->Identity];
pp=Show[dataplot,plotsquarefit,DisplayFunction->\$DisplayFunction];```

### General method (Mathematica command)

#### example

`<<DescriptiveStatistics.m`

```x={50.36,50.35,50.41,50.37,50.36,50.32,50.39,50.38,50.36,50.38}

{50.36, 50.35, 50.41, 50.37, 50.36, 50.32, 50.39, 50.38, 50.36, 50.38}```

```y={24.25,24.26,24.22,24.28,24.24,24.25,24.22,24.26,24.23,24.24}

{24.25, 24.26, 24.22, 24.28, 24.24, 24.25, 24.22, 24.26, 24.23, 24.24}```

```n=Length[x Or y]

10```

```xmean=Mean[x]

50.368```

```ymean=Mean[y]

24.245```

```sigmax=StandardDeviation[x]

0.024404```

```sigmay=StandardDeviation[y]

0.0190029```

```sdomx=sigmax/Sqrt[n]//N

0.00771722```

```sdomy=sigmay/Sqrt[n]//N

0.00600925```

```AreaAverage=N[Sqrt[(ymean^2*sdomx^2+xmean^2*sdomy^2)],1]

0.4

Back to Problems```