MASTERSHEET 
Copy/Paste Formulae for Chapter 9 Variation

>Copy the formula you need
>Paste it into the other workbook you are using
>NOTE: Do NOT alter the formulae in this workbook, these are your templates only.

1. y ∝ x  Finding the constant of variation (k)

variation[y_,k_,x_]:=k*x//N
NSolve[variation["y","k","x"]=="y",Reals]

variation[y_,k_,x_]:=k*x//N
NSolve[variation[25,"k",5]==25,Reals]

2. y∝(x^2)  Finding the constant of variation (k)

variation[y_,k_,x_]:=k*(((x))^2)//N
NSolve[variation["y","k","x"]=="y",Reals]

3. y∝(1/x)  Finding the constant of variation (k)

variation[y_,k_,x_]:=k*(1/x)//N
NSolve[variation["y","k","x"]=="y",Reals]

4. y∝Log[x]  Finding the constant of variation (k)

variation[y_,k_,x_]:=k*Log[x]//N
NSolve[variation["y","k","x"]=="y",Reals]

5. y∝Other variation  Finding the constant of variation (k)

variation[y_,k_,x_]:=k*"type other variation here such as 1/x^2"//N
NSolve[variation["y","k","x"]=="y",Reals]

6. To calculate Log Value (Log Scale) or Data Value

Solve["Log Value"==Log10["Data Value"],"solve for"]//N

Solve[-2.4==Log10["Data Value"],"Data Value"]//N

Solve["Log Value"==Log10[1000],"Log Value"]//N

7. Display a table of points from an equation/Constructing a table of values

TableForm[Table[{x,"Enter equation here"},{x,0,10,variable width}],TableHeadings->{None,{"x","y"}},TableDirections->Row]

Example:

TableForm[Table[{C,F=95C+32},{C,0,10}],TableHeadings->{None,{"C","F"}},TableDirections->Row]

TableForm[Table[{r,c=2*π*r},{r,0.0,1.0,0.1}],TableHeadings->{None,{"r","c"}},TableDirections->Row]

8. MATHEMATICA COMMANDS FOR Chapter 9 Variation separate commands

a. The Squared (x^2) Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(ev^2),rv,ev}},TableHeadings->{None,{"(ev^2)","rv","ev"}}]//N
data:=Thread[{(ev^2),rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(x^2)",Style["\tWarning: You have to change x to \!\(\*SuperscriptBox[\(X\), \(\(2\)\(\\ \)\)]\) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Squared Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

ev:={0,1,2,3,4,5,6,7,8,9,10}
rv:={1560,1555,1540,1516,1482,1438,1383,1320,1246,1163,1070}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(ev^2),rv,ev}},TableHeadings->{None,{"(ev^2)","rv","ev"}}]//N
data:=Thread[{(ev^2),rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(x^2)",Style["\tWarning: You have to change x to \!\(\*SuperscriptBox[\(X\), \(\(2\)\(\\ \)\)]\) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Squared Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

b. The X Reciprocal (( 1 )/x)Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(1/ev)//N,rv,ev}},TableHeadings->{None,{"(1/ev)","rv","ev"}}]//N
data:=Thread[{(1/ev)//N,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(1/x)",Style["\tWarning: You have to change x to (1/x) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.0000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Reciprocal (1/x) Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

ev:={2,4,6,8,10}
rv:={60,30,20,15,12}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(1/ev)//N,rv,ev}},TableHeadings->{None,{"(1/ev)","rv","ev"}}]//N
data:=Thread[{(1/ev)//N,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(1/x)",Style["\tWarning: You have to change x to (1/x) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.0000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Reciprocal (1/x) Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

c. The Logarithmic  Log x Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{Log10[ev],rv,ev}},TableHeadings->{None,{"log ev","rv","ev"}}]//N
data:=Thread[{Log10[ev],rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->Logx",Style["\tWarning: You have to change x to Logx to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with Logx Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

ev:={36032,34484,26664,41890,26893,25592,7454,1713,7073,1192,631,1302}
rv:={80.4,79.8,79.2,77.4,78.8,81.5,74.9,72.0,77.9,70.3,73.0,68.6}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{Log10[ev],rv,ev}},TableHeadings->{None,{"log ev","rv","ev"}}]//N
data:=Thread[{Log10[ev],rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->Logx",Style["\tWarning: You have to change x to Logx to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",Round[(Sqrt[lm["RSquared"]]),0.000001],Style["\tWarning: the r value is negative if the slope is negative!!",{Red,Small}]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with Logx Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

9. MATHEMATICA COMMANDS FOR Chapter 9 Variation All-in-one

If[evname=="",assigned,notassigned,evname="(ev)"];
If[rvname=="",assigned,notassigned,rvname="(rv)"];
DialogInput[Grid[{{"EV Name",InputField[Dynamic[evname],String,FieldSize->10],"EV values",InputField[Dynamic[evinput],String,FieldSize->Automatic]},{"RV Name", InputField[Dynamic[rvname],String,FieldSize->10],"RV values",InputField[Dynamic[rvinput],String]},
{"Transformation:",ButtonBar[{"None":>DialogReturn[tfmType=1],"(x^2)":>DialogReturn[tfmType=2],"Log x":>DialogReturn[tfmType=3],"(1/x)":>DialogReturn[tfmType=4],"(y^2)":>DialogReturn[tfmType=5],"Log y":>DialogReturn[tfmType=6],"(1/y)":>DialogReturn[tfmType=7]},ImageMargins->5,ImageSize->{50,40},FrameMargins->5,Background->LightBlue],SpanFromLeft,SpanFromLeft}}],WindowTitle->"Regression analysis."];
tfmlist:={{{"No transformation"},{"y","x"},{"ev","rv"}},{{"x-Squared"},{"y","(x^2)"},{"(ev^2)","rv"}},{{"(Subscript[log, 10])(x)"},{"y","(Subscript[Log, 10])(x)"},{"Log10[ev]","rv"}},{{"reciprocal x"},{"y","(1/x)"},{"(1/ev)","rv"}},{{"y-squared"},{"(y^2)","x"},{"ev","(rv^2)"}},{{"(Subscript[log, 10])(y)"},{"(Subscript[Log, 10])(y)","x"},{"ev","Log10[rv]"}},{{"reciprocal y"},{"(1/y)","x"},{"ev","(1/rv)"}}}
ev:=ImportString[evinput,"List","LineSeparators"->","]
rv:=ImportString[rvinput,"List","LineSeparators"->","]
data:=Thread[ToExpression[Part[tfmlist,tfmType,3]]]
label="Scatterplot with "<>Part[tfmlist,tfmType,1,1]<>" transformation";
xaxislabel=StringReplace[Part[tfmlist,tfmType,3,1],"ev"->evname];
yaxislabel=StringReplace[Part[tfmlist,tfmType,3,2],"rv"->rvname];
xmin=Min[ToExpression[Part[tfmlist,tfmType,3,1]]];
xmax = Max[ToExpression[Part[tfmlist,tfmType,3,1]]];
lm=LinearModelFit[Sort[data],x,x];
Print["Regression equation: ",Part[tfmlist,tfmType,2,1]," = ",Extract[Normal[lm],1],If[D[Normal[lm],x]<0," - "," + "],Abs[Extract[Normal[lm],2]/x],Part[tfmlist,tfmType,2,2],"    ( ",yaxislabel," = ",Extract[Normal[lm],1],If[D[Normal[lm],x]<0," - "," + "],Abs[Extract[Normal[lm],2]/x]," x ",xaxislabel,"  )"]
Print["Pearson's r value = ",If[D[Normal[lm],x]<0,0-(Sqrt[lm["RSquared"]]),(Sqrt[lm["RSquared"]])]]
Print["Coefficient of Determination ((r^2)) =   ",lm["RSquared"]]
Show[ListPlot[data,AxesLabel->{xaxislabel,yaxislabel}],Plot[Normal[lm],{x,xmin,xmax}],PlotLabel->If[tfmType>1,label,"Scatterplot"]]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]