Exercise 5.1 Solutions

2a.

data = {{-4, 1.2, 0.44}, {-2, 2.8, 3.34}, {0, 6.2, 6.24}, {2, 
            7.8, 9.14}, {4, 13.2, 12.04}};

n = Length[data]

TableForm[data]

Transpose[data]

TableForm[dataxy = Transpose[Take[Transpose[data], 2]]]

lsqline = Regression[dataxy]

Transpose[data][[2]]

Transpose[data][[3]]

(Transpose[data][[2]] - Transpose[
              data][[3]])^2

Sqrt[
      Apply[Plus, (Transpose[data][[2]] - Transpose[
                    data][[3]])^2]/n]

3c.

data = {{1, 1.6, 1.58}, {2, 2.8, 3.16}, {3, 4.7, 4.74}, {4, 6.4, 
            6.32}, {5, 8.0, 7.9}};

n = Length[data]

TableForm[data]

TableForm[dataxy = Transpose[Take[Transpose[data], 2]]]

pcurve = PowerCurve[dataxy, 1]

Table[pcurve /. x -> Transpose[data][[1]]]

Sqrt[
      Apply[Plus, (Transpose[data][[2]] - Transpose[
                    data][[3]])^2]/n]

9.

(a)

data = {{0.5, 7.1}, {0.8, 4.4}, {1.1, 3.2}, {1.8, 1.9}, {4.0, 
            0.9}};

n = Length[data]

TableForm[data]

g1 = 
        ListPlot[data, PlotStyle -> {Red, PointSize[0.02]}];

xs = Transpose[data][[1]]

ys = Transpose[data][[2]]

pc1 = PowerCurve[data, -1]

g2 = Plot[pc1, {x, 0.5, 4}, PlotStyle -> {Blue}];

computedys = pc1 /. x -> xs

ys - computedys

(ys - computedys)^2

Sqrt[Apply[Plus, (ys - computedys)^2]/n]

pc2 = PowerCurve[data, -2]

g3 = Plot[pc2, {x, 0.5, 4}, PlotStyle -> {Black}];

computedys = pc2 /. x -> xs

Sqrt[Apply[Plus, (ys - computedys)^2]/n]

Show[{g1, g2, g3}];

(b)

data = {{0.7, 8.1}, {0.9, 4.9}, {1.1, 3.3}, {1.6, 1.6}, {3.0, 
            0.5}};

n = Length[data]

TableForm[data]

g1 = 
        ListPlot[data, PlotStyle -> {Red, PointSize[0.02]}];

xs = Transpose[data][[1]]

ys = Transpose[data][[2]]

pc1 = PowerCurve[data, -1]

g2 = Plot[pc1, {x, 0.7, 3}, PlotStyle -> {Blue}];

computedys = pc1 /. x -> xs

Sqrt[Apply[Plus, (ys - computedys)^2]/n]

pc2 = PowerCurve[data, -2]

g3 = Plot[pc2, {x, 0.7, 3}, PlotStyle -> {Black}];

computedys = pc2 /. x -> xs

Sqrt[Apply[Plus, (ys - computedys)^2]/n]

Show[{g1, g2, g3}];

Functions Used in this notebook

Regression[XY0_]:=Module[ {k, n, XY = XY0 },
n = Length[XY];
X = (Subscript[(Transpose[XY]), [[1]]]); 
Y = (Subscript[(Transpose[XY]), [[2]]]); 
A=(({{(∑_(k = 1)^n) ((Subscript[X, [[k]]])^2), (∑_(k = 1)^n) (Subscript[X, [[k]]])}, {(∑_(k = 1)^n) (Subscript[X, [[k]]]), n}})); 
B=(({{(∑_(k = 1)^n) 
                                  (Subscript[X, [[k]]]) 
                              (Subscript[Y, [[k]]])}, {(∑_(k = 1)^n) (Subscript[Y, [[k]]])}})); 
c = LinearSolve[A, B]; 
a = 
                  (Subscript[c, [[1, 1]]]); 
b = 
                  (Subscript[c, [[2, 1]]]); 
E2 = (∑_(k = 1)^n)((((Subscript[Y, [[k]]]) - a (Subscript[X, [[k]]]) - b))^2); 
Return[ a x + b ]; ];

PowerCurve[XY0_, m_] := 
        Module[ {k, n, XY = XY0 }, 
n = 
            Length[XY]; 
X = (Subscript[(Transpose[XY]), [[1]]]);  
Y = (Subscript[(Transpose[XY]), [[2]]]);  
a = (∑_(k = 1)^n)((((Subscript[X, [[k]]])))^m) (Subscript[Y, [[k]]]) /(∑_(k = 1)^n)((((Subscript[X, [[k]]])))^(2  m)); 
Return[ 
            a (x^m)]; ];