MASTERSHEET 
Copy/Paste Formulae for Core 1 Data Analysis

>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.

A. MATHEMATICA COMMANDS FOR CORE 1 (Data) Univariate Data Chapter 1

1. To create a frequency table of data with Tally and percentage, calculate the mode CATEGORICAL DATA

dataset:={"Enter data separated by commas"}
PercentForm[WordFrequency["\",{"\","\","\"}]]
Tally[dataset]
TableForm[Tally[dataset],TableHeadings->{None, {"Column 1","Frequency"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

dataset:={S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M}
PercentForm[WordFrequency["S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M",{"S","M","L"}]]
Tally[dataset]
TableForm[Tally[dataset],TableHeadings->{None, {"Column 1","Frequency"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

dataset:={S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M}
Tally[dataset]
TableForm[Tally[dataset],FrequencyAllocation[dataset],TableHeadings->{None, {"Column 1","Frequency","Percentage"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

2. To calculate Percentage Frequency of a Frequency Table

PercentForm[Solve["Per cent"==(("Count")/("Total Count")),"Per cent"]//N]

PercentForm[Solve["Per cent"==(8/20),"Per cent"]//N]

3. To create a bar chart of data

BarChart[{"Enter frequency values in order, separated by commas"},ChartLabels->{"Enter variable names in double quotation marks and separated by commas"}, ChartStyle->{"Enter colours with a capital letter and separated by commas"}]

BarChart[{40,45,15},ChartLabels->{"S","M","L"}, ChartStyle->{Red,Green,Yellow}]

4. Stacked (Segmented) Bar Chart

BarChart[{{"category 1 segment 1","category 2 segment 1","category 3 segment 1"},{"category 1 segment 2","category 2 segment 2","category 3 segment 2"},{"category 1 segment 3","category 2 segment 3","category 3 segment 3"},{"category 1 segment 4","category 2 segment 4","category 3 segment 4"}},ChartLayout->"Stacked",ChartLegends->{"Thingies","Doohickeys","Whatsits"}]

BarChart[{{1,2,3},{1,3,6},{3,1,4},{0,6,4}},ChartLayout->"Stacked",ChartLegends->{"Thingies","Doohickeys","Whatsits"}]

5. To calculate the Mean, the Standard Deviation

dataset1:={"Enter data separated by commas"}
lm:=Round[Mean[dataset1],0.001]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset1],0.001]//N
Print["Standard Deviation = ",Normal[lm]]

dataset1:={176,160,163,157,168,172,173,169}
lm:=Round[Mean[dataset1],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset1],0.01]//N
Print["Standard Deviation = ",Normal[lm]]

6. To calculate the Five-Number Summary: Minimum, (Subscript[Q, 1]),Median, (Subscript[Q, 3]), Maximum, IQR, Box Whisker Plot, Stem Leaf Plot

dataset2:={"Enter data separated by commas"}
lm:=Min[dataset2]//N
Print["Minimum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], Quartiles[dataset2], Quartiles[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["Quartile 1, Quartile 2 could be wrong, Quartile 3= ",Normal[lm]]
lm:=Median[dataset2]//N
Print["Quartile 2 = Median = ",Normal[lm]]
lm:=Max[dataset2]//N
Print["Maximum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], InterquartileRange[dataset2], InterquartileRange[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["IQR = ",Normal[lm]]
lm:=Max[dataset2]-Min[dataset2]//N
Print["Range = ",Normal[lm]]
BoxWhiskerChart[dataset2,"Outliers",BarOrigin->Left]//N
Needs["StatisticalPlots`"]
StemLeafPlot[dataset2]

dataset2:={28,21,21,3,22,31,35,26,27,33,43,31,30,34,48,36,35,23,24}
lm:=Min[dataset2]//N
Print["Minimum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], Quartiles[dataset2], Quartiles[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["Quartile 1, Quartile 2 could be wrong, Quartile 3= ",Normal[lm]]
lm:=Median[dataset2]//N
Print["Quartile 2 = Median = ",Normal[lm]]
lm:=Max[dataset2]//N
Print["Maximum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], InterquartileRange[dataset2], InterquartileRange[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["IQR = ",Normal[lm]]
lm:=Max[dataset2]-Min[dataset2]//N
Print["Range = ",Normal[lm]]
BoxWhiskerChart[dataset2,"Outliers",BarOrigin->Left]//N
Needs["StatisticalPlots`"]
StemLeafPlot[dataset2]

7. Lower Fence  of  Box plot

Solve["Lower Fence"=="Lower Quartile"-1.5*("Upper Quartile"-"Lower Quartile"),"solve for"]

8.  Upper Fence of  Box plot

Solve["Upper Fence"=="Upper Quartile"+1.5*("Upper Quartile"-"Lower Quartile"),"solve for"]

9. To create a Histogram from a list of data

Histogram[{"Enter data separated by commas"},{"Minimum","Maximum","Enter interval spacing"},LabelingFunction->Above,PlotRange->All, ChartLabels->{"\"}, AxesLabel->{"\","\"}]

Histogram[{86,82,96,71,90,78,68,71,68,88,76,74,70,78,69,77,64,80,83,78,88,70,86},{63,98,2},LabelingFunction->Above,PlotRange->All, ChartLabels->{"23 Students Pulse Rates"}, AxesLabel->{"Student Number","Pulse Rate"}]

10. To create a Percentage Histogram from a list of data

rawdata={"Enter data separated by commas"};
bins={Range["Minimum","Maximum","Enter interval spacing"]};
Histogram[rawdata,bins,"Probability",LabelingFunction->(Placed[Panel[PercentForm[Round[#1,0.0001]],FrameMargins->0],Above]&),Ticks->{First@bins,Table[{.01 i,If[Mod[i,5]==0,ToString[i]<>"%",""]},{i,100}]}]

rawdata={86,82,96,71,90,78,68,71,68,88,76,74,70,78,69,77,64,80,83,78,88,70,86};
bins={Range[0,100,10]};
Histogram[rawdata,bins,"Probability",LabelingFunction->(Placed[Panel[PercentForm[Round[#1,0.0001]],FrameMargins->0],Above]&),Ticks->{First@bins,Table[{.01 i,If[Mod[i,5]==0,ToString[i]<>"%",""]},{i,100}]}]

11. 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

12. To create a Log Histogram With Log Scale

Histogram[{"Enter data separated by commas"},{"Log","Width Specification"},LabelingFunction->Above,PlotRange->All]

Histogram[{1.4,470,36,28,1.0,12000,2600,190,520,10,3.3,530,210,62,6700,9400,6.8,35,0.12,0.023,2.5,56,100,52,87000,0.12,190},{"Log",6},LabelingFunction->Above,PlotRange->All]

13. To create a Stem and Leaf Plot with split stems

Needs["StatisticalPlots`"]
StemLeafPlot[{"Enter data separated by commas"},StemExponent->{Automatic,"UnitDivisions"->2,"DivisionLabels"->{"L","H"}},IncludeStemCounts->True,IncludeEmptyStems->True]

Needs["StatisticalPlots`"]
StemLeafPlot[{16.9,17.3,19.3,18.5,18.2,18.4,19.9,16.7,17.7,16.5,17.0,17.2,17.6,17.1,17.6},StemExponent->{0,"UnitDivisions"->2,"DivisionLabels"->{"L","H"}},IncludeStemCounts->True,IncludeEmptyStems->True]

14. To create a back-to-back Stem and Leaf Plot from two lists of data

Needs["StatisticalPlots`"]
StemLeafPlot[{"Enter data separated by commas"},{"Enter data separated by commas"},StemExponent->Automatic,IncludeStemCounts->True,IncludeEmptyStems->True]

Needs["StatisticalPlots`"]
StemLeafPlot[{16.9,17.3,19.3,18.5,18.2,18.4,19.9,16.7,17.7,16.5,17.0,17.2,17.6,17.1,17.6},StemExponent->0,IncludeStemCounts->True,IncludeEmptyStems->True]

15. To create Parallel Box plots from two lists of data

BoxWhiskerChart[{{"Enter data separated by commas"},{"Enter data separated by commas"}},"Outliers",BarOrigin->Left,ChartLabels->{"\","\"}]//N

16. Normal Distribution ( Z-Score)

Solve[z-score==(((Raw Score-Mean))/("Standard Deviation")),solvefor]

Solve[z==(((18-20.65))/5.73),z]

Solve[.6==(((x-20.65))/5.73),x]

17. Random allocation

RandomSample[{"Enter data separated by commas"},"number of data samples needed"]

RandomSample[{Van, Razi, Gemma,Nimmi, Wong, George,Harry, Zev, Lillie, Lysette, Freya, Simmon, Anna, Mei, Emma, Ali, Moh, Trang, Lani, Sophie},10]

18. Generating a set of normally distributed data

dataset3:=RandomVariate[NormalDistribution["Mean","Standard Deviation"],"number of data samples needed"]
lm:=Round[Mean[dataset3],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset3],0.01]//N
Print["Standard Deviation = ",Normal[lm]]
Histogram[{dataset3},{1}]

dataset3:=RandomVariate[NormalDistribution[25,5],200]
lm:=Round[Mean[dataset3],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset3],0.01]//N
Print["Standard Deviation = ",Normal[lm]]
Histogram[{dataset3},{1}]

The distribution is approximately symmetric and bell shaped.

B. MATHEMATICA COMMANDS FOR CORE 1 (Data) Bivariate Data Chapter 2 & 3

1. To create a Scatter Plot (with Regression Line), Residual Plot of Data, calculate Regression Equation, Pearson’s r Value, Coefficient of Determination EV=Explanatory Variables; RV= Response Variables

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

ev:={88.7,67.0,77.5,61.7,86.8,32.4,72.4,77.1,86.5}
rv:={0.3,1.3,2.8,7.6,1.2,5.7,9.4,10.0,0.7}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"- ",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

2. Finding the equation of the line from two points (x1,y1) and (x2,y2) along the line

lm=LinearModelFit[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])}},x,x]
Print["Equation:    y = ",Normal[lm]]

Example
Find the equation of the line that passes through the points (0,3) and (2,2)
lm=LinearModelFit[{{0,3},{2,2}},x,x]
Print[“Equation:    y = “,Normal[lm]]
FittedModel[3.` -0.5` x]
Equation: y = 3 - 0.5x

3. Predict a value from a given equation

Solve["y  RV (Response Variable)"=="y-intercept"+"Slope"*"x  EV (Explanatary Variable)","solve for"]

Example
Predict the value of x = 3 for the equation y = 3 - 0.5x
y=3-0.5x/.x->3
1.5`

4. Calculating slope b by r value,  Sx EV  standard deviation & Sy RV standard deviation

slope[r_,Sx_,Sy_]:=((r*Sy)/Sx)
NSolve[slope["r value Correlation coefficient","Sx Standard deviation of EV","Sy Standard deviation of RV"]=="Slope value",Reals]

slope[r_,Sx_,Sy_]:=((r*Sy)/Sx)
NSolve[slope["r value Correlation coefficient",4.29,1.69]==0.312,Reals]

5. Calculating intercept a by  slope b, (OverTilde[x]) EV mean & (OverTilde[y]) RV mean

intercept[b_,x_,y_]:=y-b*x
NSolve[intercept["Slope b Value","Mean of EV \!\(\*OverscriptBox[\(x\), \(~\)]\)","Mean of RV \!\(\*OverscriptBox[\(y\), \(~\)]\)"]=="intercept a",Reals]

intercept[b_,x_,y_]:=y-b*x
NSolve[intercept[-0.408,18.0,15.7]=="intercept a",Reals]

C. MATHEMATICA COMMANDS FOR CORE 1 (Data) Data Transformation Chapter 4

1. The New Transformation (Needing high speed laptop)

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"]

2.1. 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 = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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"]

2.2. The Squared (y^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,(rv^2),rv}},TableHeadings->{None,{"ev","(rv^2)","rv"}}]//N
data:=Thread[{ev,(rv^2)}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    (y^2) = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Y Squared Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.3. 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 = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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"]

2.4. The Logarithmic  Log y Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{ev,Log10[rv],rv}},TableHeadings->{None,{"ev","log rv","rv"}}]//N
data:=Thread[{ev,Log10[rv]}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    Logy = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Logy Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.5. 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 = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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"]

2.6. The Y Reciprocal (( 1 )/y) Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{ev,(1/rv)//N,rv}},TableHeadings->{None,{"ev","(1/rv)","rv"}}]//N
data:=Thread[{ev,(1/rv)//N}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    (1/y) = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
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,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Y Reciprocal (1/y) Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

D. MATHEMATICA COMMANDS FOR CORE 1 (Data) Time Series Chapter 5

1.Constructing time series plots one graph and two graphs on one plane

a. One time series plot

ev:= {"insert EV data here, separated by commas"}
rv:={"insert RV data here, separated by commas"}
data:=Thread[{ev,rv}]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{ev,rv}]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]

b. Two Time Series plots on one

ev:= {"insert EV data here, separated by commas"}
rv:={"insert RV data here, separated by commas"}
rv1:={"insert RV data here, separated by commas"}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,rv1}]
Show[ListLinePlot[{data,data1}],ListPlot[{data,data1}]]

ev:= {1993,1994,1995,1996,1997,1998,1999,2000,2001}
rv:={139.9,141.2,145.5,148.5,152.5,156.0,163.4,167.4,172.5}
rv1:={77.9,76.6,75.3,75.0,74.9,74.9,76.0,76.6,77.1}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,rv1}]
Show[ListLinePlot[{data,data1}],ListPlot[{data,data1}]]

2. Smoothing with Moving-Mean

n:="if a 3-moving-mean, enter a 3 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,movingmean},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmean],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

n:=3
xdata:={1,2,3,4,5,6,7,8,9,10,11,12}
ydata:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,movingmean},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmean],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

3. Smoothing with Moving-Mean and Centring

n:="if a 2-moving-mean with centring, enter a 2 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,MovingAverage[movingmean,2]},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[MovingAverage[movingmean,2]],TableHeadings->{None,{"x value","y value\n (smoothed and centred)"}}]]

n:=4
xdata:={1,2,3,4,5,6,7,8,9,10,11,12}
ydata:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,MovingAverage[movingmean,2]},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[MovingAverage[movingmean,2]],TableHeadings->{None,{"x value","y value\n (smoothed and centred)"}}]]

4. Smoothing with Moving Median

n:="if a 3 median smoothing, enter a 3 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmedian:=N[Thread[{MovingMedian[xdata,n],MovingMedian[ydata,n]}]]
Print[ListLinePlot[{data,movingmedian},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmedian],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

5. Comparing 3-Moving and 5-Moving Smoothing Mean/Median

method1:="... -moving smoothing"
method2:="... -moving smoothing"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{Moving"Average or Median"[xdata,method1],Moving"Average or Median"[ydata,method1]}]]
movingmethod2:=N[Thread[{Moving"Average or Median"[xdata,method2],Moving"Average or Median"[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Example 1(Mean):

method1:=3
method2:=5
xdata:={1,2,3,4,5,6,7,8,9,10}
ydata:={0.743,0.754,0.737,0.751,0.724,0.724,0.712,0.735,0.716,0.711}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{MovingAverage[xdata,method1],MovingAverage[ydata,method1]}]]
movingmethod2:=N[Thread[{MovingAverage[xdata,method2],MovingAverage[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Example 2(Median):

method1:=3
method2:=5
xdata:={1,2,3,4,5,6,7,8,9,10,11,12,13}
ydata:={6,4.2,2,4.5,4.2,4,1,-2,3,4,4.5,3.6,3.9}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{MovingMedian[xdata,method1],MovingMedian[ydata,method1]}]]
movingmethod2:=N[Thread[{MovingMedian[xdata,method2],MovingMedian[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Answer 2b: The plot of the raw data, which is essentially a plot of GDP growth smoothed over 1 year, shows a great deal of variability over the whole time period.No clear trend is apparent.When smoothed over a 3 - year period, GDP growth is still variable but to a lesser extent.No clear trend is apparent, but GDP appears to be going through a period of below average growth during the time period Year 7 to Year 9.When smoothed over a 5 - year period, GDP growth is much less variable but clearly shows the period of below average growth during the period Year 7 to Year 9.

6. Seasonal Indices

a. One time period to calculate Seasonal Index

ev:= {"insert EV data here, separated by commas"}
rv:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"1\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,Round[(rv/(Round[(rv/(Mean[rv])),0.01])),0.01]}];
TableForm[{{ev,rv,Round[(rv/(Mean[rv])),0.01],Round[(rv/(Round[(rv/(Mean[rv])),0.01])),0.1]}},TableHeadings->{None,{"ev","rv","Seasonal Index","Deseasonalised value"}}]//N
Show[ListLinePlot[{data,data1}]]

ev:= {1,2,3,4}
rv:={60,56,75,78}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,Round[(rv/(Round[(rv/(Mean[rv])),0.01])),0.01]}];
TableForm[{{ev,rv,Round[(rv/(Mean[rv])),0.01],Round[(rv/(Round[(rv/(Mean[rv])),0.01])),0.1]}},TableHeadings->{None,{"ev","rv","Seasonal Index","Deseasonalised value"}}]//N
Show[ListLinePlot[{data,data1}]]

b. two time time periods to calculate Seasonal Index

ev:= {"insert EV data here, separated by commas"}
rv:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"1\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
rv1:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"2\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
data:=Thread[{ev,rv}]
data1=Thread[{ev+"Insert number of Quarter/Month/Week here",rv1}]
data3:=Thread[{ev,Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),0.1]}]
data4:=Thread[{ev+"Insert number of Quarter/Month/Week here",Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),0.1]}];
TableForm[{{ev,rv,rv1,Round[(rv/(Mean[rv])),0.01],Round[(rv1/(Mean[rv1])),0.01],Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.01],Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.01])),0.1],Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.01])),0.1]}},TableHeadings->{None,{"ev","rv","rv1","rv S.I.","rv1 S.I.","S.I.","rv D.S.L.","rv1 D.S.L."}}]//N
Show[ListLinePlot[{data,data1,data3,data4}]]

ev:= {1,2,3,4,5,6,7}
rv:={124,110,45,67,230,134,330}
rv1:={120,108,57,74,215,150,345}
data:=Thread[{ev,rv}]
data1=Thread[{ev+7,rv1}]
data3:=Thread[{ev,Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),0.01]}]
data4:=Thread[{ev+7,Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),0.01]}];
TableForm[{{ev,rv,rv1,Round[(rv/(Mean[rv])),0.01],Round[(rv1/(Mean[rv1])),0.01],Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.01],Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),1],Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1])))/2),0.1])),1]}},TableHeadings->{None,{"ev","rv","rv1","rv Seasonal Index","rv1 Seasonal Index","Seasonal Index","rv Deseasonalised value","rv1 Deseasonalised value"}}]//N
Show[ListLinePlot[{data,data1,data3,data4}]]

c. three time time periods to calculate Seasonal Index

ev:= {"insert EV data here, separated by commas"}
rv:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"1\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
rv1:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"2\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
rv2:={"Insert Quarter/Month/Week \!\(\*StyleBox[\"3\",FontColor->RGBColor[1, 0, 0]]\) data here, separated by comma"}
data:=Thread[{ev,rv}]
data1=Thread[{ev+"Insert number of Quarter/Month/Week here",rv1}]
data2=Thread[{ev+2*"Insert number of Quarter/Month/Week here",rv2}]
data3:=Thread[{ev,Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}]
data4:=Thread[{ev+"Insert number of Quarter/Month/Week here",Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}]
data5:=Thread[{ev+2*"Insert number of Quarter/Month/Week here",Round[(rv2/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}];
TableForm[{{ev,rv,rv1,rv2,Round[(rv/(Mean[rv])),0.001],Round[(rv1/(Mean[rv1])),0.001],Round[(rv2/(Mean[rv2])),0.001],Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01],Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1],Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1],Round[(rv2/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1]}},TableHeadings->{None,{"ev","rv","rv1","rv2","rv S.I.","rv1 S.I.","rv2 S.I.","S.I.","rv D.S.L.","rv1 D.S.L.","rv2 D.S.L."}}]//N
Show[ListLinePlot[{data,data1,data2,data3,data4,data5}]]

ev:= {1,2,3,4}
rv:={212,194,196,227}
rv1:={220,197,196,239}
rv2:={231,205,203,245}
data:=Thread[{ev,rv}]
data1=Thread[{ev+4,rv1}]
data2=Thread[{ev+2*4,rv2}]
data3:=Thread[{ev,Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}]
data4:=Thread[{ev+4,Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}]
data5:=Thread[{ev+2*4,Round[(rv2/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.1])),1]}];
TableForm[{{ev,rv,rv1,rv2,Round[(rv/(Mean[rv])),0.001],Round[(rv1/(Mean[rv1])),0.001],Round[(rv2/(Mean[rv2])),0.001],Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01],Round[(rv/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1],Round[(rv1/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1],Round[(rv2/(Round[(((rv/(Mean[rv]))+(rv1/(Mean[rv1]))+(rv2/(Mean[rv2])))/3),0.01])),1]}},TableHeadings->{None,{"ev","rv","rv1","rv2","rv S.I.","rv1 S.I.","rv2 S.I.","S.I.","rv D.S.L.","rv1 D.S.L.","rv2 D.S.L."}}]//N
Show[ListLinePlot[{data,data1,data2,data3,data4,data5}]]

7.Constructing time series plots, Calculating a Regression Equation, Fitting a least-squares line to a time series

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListLinePlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

Example 1:

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={2149,2140,2124,2118,2118,2114,2091,2064,2059,2038,2029,2013}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]
Show[ListLinePlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,1,12}],PlotLabel->"Scatterplot with Regression Line"]

Example 2:

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={893,943,955,858,1005,1026,1043,1040,1261,1151,1115,1267}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,1,12}],PlotLabel->"Scatterplot with Regression Line"]

8. Equation of Least Squares Regression Line: Substitute values of x (EV) in the equation below to make predictions

Solve["Predicted Value"=="yintercept"+"slope"*"x-value","solve for"]//N

MASTERSHEET 
Copy/Paste Formulae for Core 2 Finance

>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.

MATHEMATICA COMMANDS FOR CORE 2 Recursion and financial modelling

1. Generating a TABLE Graph of a sequence Compound interest Investment or Annuity Investment.

f[x_]:="Common Ratio" x+"Common Difference"
NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]]

Example Use a calculator to generate the first five terms of the sequence with a starting value of 5 and the rule 'double and then subtract 3'.

f[x_]:=2 x+-3
NestList[f, 5,( 4)]//FullForm
ListPlot[NestList[f, 5,( 4)]]

2. Calculating effective interest rates

effectiverate[r_,n_]:=((((1+((r/n)/100)))^n)-1.)*100
NSolve[effectiverate["nominal rate (% p.a.)","Number of payment per year"]=="effective interest rate",Reals]//FullForm

Example Marissa has $10000 to invest.She chooses an account that will earn compounding interest at the rate of 4.5 % per annum, compounding monthly.Use a CAS calculator to find the effective rate for this investment, correct to three decimal places.

effectiverate[r_,n_]:=((((1+((r/n)/100)))^n)-1.)*100
NSolve[effectiverate[4.5,12]=="effective interest rate",Reals]//FullForm

The effective rate is 4.594 %

3. Financial Solver for Future Value and Regular Payment

a. Repayment for Interest Only Loan or Perpetuity. Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) - "Interest in dollars (Common Difference)"

repayment[prin_,r_,n_]:=((((r/n)))/100)prin
NSolve[repayment["Principal","Rate per annum","Number of payment per year"]=="Payment",Reals]//FullForm

b. Reduced Balance Loan or Annuity.  Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) - "Interest in dollars (Common Difference)"

futurevalue[prin_,r_,n_,t_,payt_]:=prin(((1+((((r/n)))/100)))^((n*t)))- payt*(((((((1+((((r/n)))/100)))^((n*t)))-1))/((((((r/n)))/100)))))
NSolve[futurevalue["Principal","Rate per annum","Number of payment per year","Time in YEARS","Payment"]==Future Value,Reals]//FullForm

c. Compound interest investments with regular additions to the principal (annuity investment).  Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) +  "Interest in dollars (Common Difference)"

futurevalue[prin_,r_,n_,t_,payt_]:=prin(((1+((((r/n)))/100)))^((n*t)))+ payt*(((((((1+((((r/n)))/100)))^((n*t)))-1))/((((((r/n)))/100)))))
NSolve[futurevalue["Principal","Rate per annum","Number of payment per year","Time in YEARS","Payment"]==Future Value,Reals]//FullForm

d. Generating a TABLE Graph of a sequence Reduced balance Loan/Annuity/Interest Only/Perpetuity

f[x_]:="Common Ratio" x-"Common Difference"
NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]]

4. Amortisation Tables

a.To find Payment for Reduced Balance Loan or Annuity

l[0]="Principal";
rate="Annual interest rate"/100;
loanpayment="payment amount";
l[t_]:=l[t-1]*(1+(rate/"number of compounding periods per year"))-loanpayment;Grid[Partition[Flatten[Prepend[Table[{t,loanpayment,DecimalForm[(l[t-1]*(rate/"number of compounding periods per year".)),{∞,2}],DecimalForm[loanpayment-(l[t-1]*(rate/"number of compounding periods per year".)),{∞,2}],DecimalForm[l[t],{∞,2}]},{t,1,"number of payments"}],{"Payment\nnumber","Payment\namount","Interest\npaid","Principal\nreduction","Loan\nBalance"}]],5], Background -> {None,{{Yellow, None,None,None,None,None}}},Frame->True]

b.To find Payment for Compound interest investments with regular additions to the principal (annuity investment)

l[0]="Principal";
rate="Annual interest rate"/100;
loanpayment="payment amount";
l[t_]:=l[t-1]*(1+(rate/"number of compounding periods per year"))+loanpayment;Grid[Partition[Flatten[Prepend[Table[{t,loanpayment,DecimalForm[(l[t-1]*(rate/"number of compounding periods per year".)),{∞,2}],DecimalForm[loanpayment+(l[t-1]*(rate/"number of compounding periods per year".)),{∞,2}],DecimalForm[l[t],{∞,2}]},{t,1,"number of payments"}],{"Payment\nnumber","Payment\namount","Interest\npaid","Principal\naddiction","Loan\nBalance"}]],5], Background -> {None,{{Yellow, None,None,None,None,None}}},Frame->True]

l[0]=1000;
rate=5/100;
loanpayment=257.85;
l[t_]:=l[t-1]*(1+(rate/4))-loanpayment;Grid[Partition[Flatten[Prepend[Table[{t,loanpayment,DecimalForm[(l[t-1]*(rate/4.)),{∞,2}],DecimalForm[loanpayment+(l[t-1]*(rate/4.)),{∞,2}],DecimalForm[l[t],{∞,2}]},{t,1,4}],{"Payment\nnumber","Payment\namount","Interest\npaid","Principal\naddiction","Loan\nBalance"}]],5], Background -> {None,{{Yellow, None,None,None,None,None}}},Frame->True]

5. Finding the common ratio (R) given the percentage reduction

ratio[R_,r_]:=(1-(r/100))//N
NSolve[ratio["common ratio (R)","Rate"]=="common ratio (R)",Reals]

ratio[R_,r_]:=(1-(r/100))//N
NSolve[ratio[x,4]==x,Reals]

6. Finding the common ratio (R) given the percentage increase

ratio[R_,r_,p_]:=(1+(r/(100p)))//N
NSolve[ratio["common ratio (R)","Rate per annum","Number of payment per year"]=="common ratio (R)",Reals]

ratio[R_,r_,p_]:=(1+(r/(100p)))//N
NSolve[ratio["common ratio (R)",4,1]=="common ratio (R)",Reals]

7. Simple Interest

a. Finding interest in dollars ( Common difference) for  Simple Interest

difference[V0_,r_,p_,D_]:=(r/(100p))*V0//N
NSolve[difference["Principal","Rate per annum","Number of payment per year","Interest in dollars (Common Difference)"]=="Interest in dollars (Common Difference)",Reals]

b. Generate a table and graph of Simple Interest--Recurrence Relation (Subscript[V, 0])="Principal", (Subscript[V, n+1])= (Subscript[V, n])+ "Interest in dollars (Common Difference)". 
Explicit Rule: (Subscript[V, n])= "Principal"+ n *"Interest in dollars (Common Difference)"

f[x_]:=x+"Interest in dollars (Common Difference)"
NestList[f, "Principal",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Principal", ("Number of payment per year"*"Time in YEARS")]]

c. Explicit Rule Calculation for Simple Interest

nthvalue[V0_,r_,p_,n_]:=V0+n*p*(r/(100p))*V0
NSolve[nthvalue["Principal","Rate per annum","Number of payment per year","Time in YEARS"]==Future Value,Reals]

8. Compound Interest

a. Finding Common Ratio for  Compound Interest

ratio[R_,r_,p_]:=(1+(r/(100p)))//N
NSolve[ratio["common ratio (R)","Rate per annum","Number of payment per year"]=="common ratio (R)",Reals]

b. Generate a table and graph of Compound Interest--Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]). 
Explicit Rule: (Subscript[V, n])= "Principal"* (("Common Ratio")^n)

f[x_]:="Common Ratio" x
NestList[f, "Principal",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Principal",( "Number of payment per year"*"Time in YEARS")]]

c. Explicit Rule Calculation for Compound Interest

nthvalue[V0_,r_,p_,n_]:=V0*(1+(r/(100p)))^(n*p)
NSolve[nthvalue["Principal","Rate per annum","Number of payment per year","Time in YEARS"]==Future Value,Reals]//FullForm

9. Flat Rate Depreciation

a. Finding depreciation value in dollars ( Common difference) for  Flat Rate Depreciation

difference[V0_,r_,p_,D_]:=(r/(100p))*V0//N
NSolve[difference["Initial Value","Rate per annum","Number of payment per year","Depreciation value (Common Difference)"]=="Depreciation value (Common Difference)",Reals]

b. Generate a table and graph of Flat Rate Depreciation--Recurrence Relation: (Subscript[V, 0])="Initial Value", (Subscript[V, n+1])=(Subscript[V, n]) - "Depreciation value (Common Difference)". 
Explicit Rule: (Subscript[V, n])= "Initial Value" - n x "Depreciation value (Common Difference)"

f[x_]:=x-"Depreciation value (Common Difference)"
NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Initial Value", ("Number of payment per year"*"Time in YEARS")]]

c. Explicit Rule Calculation for Flat Rate Depreciation

nthvalue[V0_,p_,n_,D_]:=V0-n*p*D
NSolve[nthvalue["Initial Value","Number of payment per year","Time in YEARS","Depreciation value (Common Difference)"]==Future Value,Reals]

10. Unit Cost Depreciation

a. Generate a table and graph of Unit Cost Depreciation--Recurrence Relation: (Subscript[V, 0])= "Initial Value", (Subscript[V, n+1])=(Subscript[V, n]) - "Depreciation Cost per unit in Dollars". 
Explicit Rule: (Subscript[V, n])= "Initial Value"  - n x "Depreciation Cost per unit in Dollars"

f[x_]:=x-"Depreciation Cost per unit in Dollars"
NestList[f, "Initial Value",( "Total units ( kilometres, pages, per thousand km etc)")]
ListPlot[NestList[f, "Initial Value", ("Total units ( kilometres, pages, per thousand km etc)")]]

b. Explicit Rule Calculation for Unit Cost Depreciation

nthvalue[V0_,n_,D_]:=V0-n*D
NSolve[nthvalue["Initial Value","Total units ( kilometres, pages, per thousand km etc)","Depreciation Cost per unit in Dollars"]==Future Value,Reals]

nthvalue[V0_,n_,D_]:=V0-n*D
NSolve[nthvalue[60000,"Total units ( kilometres, pages, per thousand km etc)",0.35]==15000,Reals]

11. Reduced Balance Depreciation

a. Finding Common Ratio for  Reduced Balance Depreciation

ratio[R_,r_,p_]:=(1-(r/(100p)))//N
NSolve[ratio["common ratio (R)","Rate per annum","Number of payment per year"]=="common ratio (R)",Reals]

b. Generate a table and graph of Reduced balance Depreciation--Recurrence Relation: (Subscript[V, 0])="Initial Value", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]). 
Explicit Rule: (Subscript[V, n])= "Initial Value"* (("Common Ratio")^n)

f[x_]:="Common Ratio" x
NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]
ListPlot[NestList[f, "Initial Value",( "Number of payment per year"*"Time in YEARS")]]

c. Explicit Rule Calculation for Reduced balance Depreciation

nthvalue[V0_,r_,p_,n_]:=V0*(1-(r/(100p)))^(n*p)
NSolve[nthvalue["Initial Value","Rate per annum","Number of payment per year","Time in YEARS"]==Future Value,Reals]//FullForm

12. New Final Payment,  Total payment and Total Interest for Reduced Balance Loan or Annuity

a. New Final payment for Reduced Balance Loan or Annuity.  Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) - "Interest in dollars (Common Difference)"

finalpayment[prin_,r_,n_,t_,payt_]:=(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))*(((((r/n)))/100))
NSolve[finalpayment["Principal","Rate per annum","Number of payment per year","Time in YEARS","Payment"]=="The Final Payment",Reals]//FullForm

b. Total payment for Reduced Balance Loan or Annuity.  Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) - "Interest in dollars (Common Difference)"

totalpayment[prin_,r_,n_,t_,payt_]:=payt*(n*t-1)+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))*(((((r/n)))/100))
NSolve[totalpayment["Principal","Rate per annum","Number of payment per year","Time in YEARS","Payment"]=="The Total Payment",Reals]//FullForm

c. Total Interest  for Reduced Balance Loan or Annuity.  Recurrence Relation: (Subscript[V, 0])="Principal", (Subscript[V, n+1])="Common Ratio" *(Subscript[V, n]) - "Interest in dollars (Common Difference)"

totalinterest[prin_,r_,n_,t_,payt_]:=payt*(n*t-1)+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))*(((((r/n)))/100))-prin
NSolve[totalinterest["Principal","Rate per annum","Number of payment per year","Time in YEARS","Payment"]=="The Total Interest in dollars",Reals]//FullForm

13. Total Interest for Partial time period of Reduced Balance Loan or Annuity

totalinterest[prin_,r_,n_,s_,t_,payt_]:=payt*(n*t-1)+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))+(prin(((1+((((r/n)))/100)))^((n*(t-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(t-(1/n)))))-1))/((((((r/n)))/100))))))*(((((r/n)))/100))-(payt*(n*s-1)+(prin(((1+((((r/n)))/100)))^((n*(s-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(s-(1/n)))))-1))/((((((r/n)))/100))))))+(prin(((1+((((r/n)))/100)))^((n*(s-(1/n)))))- payt*(((((((1+((((r/n)))/100)))^((n*(s-(1/n)))))-1))/((((((r/n)))/100))))))*(((((r/n)))/100)))
NSolve[totalinterest["Principal","Rate per annum","Number of payment per year","Beginning of Time period in Years","Ending of Time period in Years","Payment"]=="The Total Interest in dollars",Reals]//FullForm

MASTERSHEET
Copy/Paste Formulae for Module 1 Matrices

>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.

MATHEMATICA COMMANDS FOR Module 1 Matrices

1. Three ways to write Matrices

a. Method 1

{{"row 1 elements"},{"row 2 elements"}}//MatrixForm

{{a,b,c}, {d,e,f}}//MatrixForm

b. Method 2

Top tool bar: Insert > Table/Matrix >New... >Create Matrix with row numbers and column numbers, for example 3X3, then fill elements in your new Matrix:

(({{\[Placeholder], \[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder], \[Placeholder]}}))

c. Method 3

Top tool bar: Palettes  > Basic Math Assistant > Basic Commands

2. Define a matrix with an upper case letter

Examples:

A=(({{a, b, c}, {d, e, f}}))

B=(({{1, 0, -7, 2}, {5, 5, 5, 5}, {-4, 3, 2, 0}}))

F=(({{2, 4}, {1, 7}}))

3. Adding, Subtracting, Scalar Multiple, Transposing Matrices

a. Adding Matrices

"matrix 1"+"matrix 2"//MatrixForm

F+(({{1, 2}, {3, 4}}))//MatrixForm

b. Subtracting Matrices

"matrix 1"-"matrix 2"//MatrixForm

F-(({{1, 2}, {3, 4}}))//MatrixForm

c. Scalar Multiple

"scalar number"×"matrix"//MatrixForm

3(({{2, 4}, {1, 7}}))//MatrixForm

d. Transposing Matrix

Transpose["matrix"]//MatrixForm

Transpose[(({{1, 2}, {3, 4}}))]//MatrixForm

4. Two Matrices Multiplication, Powers of Matrices

a. Multiplication with a dot in between

"matrix 1"."matrix 2"//MatrixForm

(({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})).(({{2, 3, 4}, {3, 4, 5}, {5, 6, 7}}))//MatrixForm

b. Powers

MatrixPower["matrix","powers"]//MatrixForm

Example 1: (G^3)

MatrixPower[G,3]//MatrixForm

5. Identity,  Inverse matrices and Determinant of a Matrix

a. Identity Matrix

IdentityMatrix["row or column numbers"]//MatrixForm

IdentityMatrix[3]//MatrixForm

b. Inverse Matrix

Inverse["matrix"]//MatrixForm

Inverse[(({{1, 2}, {3, 4}}))]//MatrixForm

c. Complicated Inverse Calculation

mA="the 1st matrix know";
mB="the 2nd matrix know";
mC="the 3rd matrix know";
mD="the 4th matrix know";
Inverse["Calculation inside INVERSE brackets"]//MatrixForm

mA=(({{3, -1}, {4, 5}}));
mB=(({{-7, 2}, {3, 1}}));
mC=(({{-4, 9}, {6, 8}}));
mD=(({{0, 8}, {4, -1}}));
(mA.mB+Inverse[mD])//MatrixForm

d. Determinant of a Matrix

determinant[det_,x_]:=Det["matrix"]//N
NSolve[determinant["the value of Determinant","the unknown letter, if a matrix given, just type any number in matrix here"]=="the value of Determinant",Reals]

determinant[det_,x_]:=Det[(({{1, 2}, {m, 4}}))]//N
NSolve[determinant[0,m]==0,Reals]

determinant[det_,x_]:=Det[(({{1, 2}, {3, 4}}))]//N
NSolve[determinant["the value of Determinant",1]=="the value of Determinant",Reals]

6. Using Matrices to Solve Simultaneous Equations

a. LinearSolve: Determinant = 0 means no solution or non-unique solutions

LinearSolve["Left side of standard equations - coefficient matrix","Right side of standard equations - constant matrix"]//MatrixForm

LinearSolve[(({{2, 3}, {1, -2}})),(({{6}, {4}}))]//MatrixForm//N

b. Alternatively

Solve[{equation here number one,another equation here},{variable1,variable2}]

Solve[{2x+3y==6,x-2y==4},{x,y}]//N

c. Given Matrices, write Equations

eqns=Thread["Left side of standard equations - coefficient matrix"."unknown matrix"=="Right side of standard equations - constant matrix"]

eqns=Thread[(({{1, 1, 1}, {1, 0, 1}, {0, 1, 1}})).(({{x}, {y}, {z}}))==(({{6}, {4}, {5}}))]

d. Given Equations, write Matrices

l={"Write all equations here, separate by comma, each equation needs two == signs"};
lm=CoefficientArrays[l,{"Write all unknown letters here, separate by comma,"}][[2]]//MatrixForm
Print[Normal[lm],{"Write all unknown letters here, separate by comma,"}//MatrixForm, "= Write right side of the equations constant numbers in a column matrix here"]

l={x-y-z==0,x+2 y+z==1,x+2y+5z==5};
lm=CoefficientArrays[l,{x,y,z}][[2]]//MatrixForm
Print[Normal[lm],{x,y,z}//MatrixForm, "= Write right side of the equations constant numbers in a column matrix here"]

(({{1, -1, -1}, {1, 2, 1}, {1, 2, 5}}))(({{x}, {y}, {z}}))= (({{0}, {1}, {5}}))

7. Recurrence tables of Matrices from the first Matrix/ Transition Matrices/Leslie Matrics

lindiff[n_]:= "Transition Matrix".n + "Extra Matrix"
NestList[lindiff,"Initial Matrix","How many more Matrices"]//MatrixForm//N

lindiff[n_]:= (({{0.7, 0.2, 0.1}, {0.1, 0.5, 0.4}, {0.2, 0.3, 0.5}})).n + (({{100}, {200}, {300}}))
NestList[lindiff,(({{1100}, {1200}, {1300}})),3]//MatrixForm//N

lindiff[n_]:= (({{0.96, 0.05}, {0.04, 0.95}})).n 
NestList[lindiff,(({{700}, {900}})),11]//MatrixForm//N

geometric[n_]:= (({{0.92, 0.01, 0.01, 0.01}, {0.02, 0.95, 0.01, 0.02}, {0.04, 0.02, 0.97, 0.03}, {0.02, 0.02, 0.01, 0.94}})).n +(({{750}, {875}, {1025}, {825}}))
NestList[geometric,(({{35500}, {43500}, {51000}, {42000}})),11]//MatrixForm//N

geometric[n_]:=(({{0.75, 0.30}, {0.25, 0.70}})).n 
NestList[geometric,(({{200}, {300}})),11]//MatrixForm//N

8. Dominance/ Ranking D+(D^2)

K="matrix 1"
K+MatrixPower[K,2]//MatrixForm//MatrixForm

K=(({{0, 1, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 1}, {1, 0, 1, 0}}))
K+MatrixPower[K,2]//MatrixForm//MatrixForm

9. Find Previous Matrix from new/next Matrix/ Transition Matrices

Inverse["Transition Matrix"].("Next Matrix"-"Extra Matrix")//MatrixForm

Inverse[(({{0.1, 0.2, 0.5}, {0.3, 0.7, 0.2}, {0.6, 0.1, 0.3}}))].((({{9830}, {11130}, {7830}}))-(({{70}, {70}, {70}})))//MatrixForm

10. Solving Equations for Matrices

mA="the 1st matrix know";
mB="the 2nd matrix know";
mC="the 3rd matrix know";
mD="the 4th matrix know";
mE="the 5th matrix know";
mX=Array[X,{"the row number of unknow","the column number of unknow"}]
Solve["left side of the equation"=="right side of the equation",Flatten[mX]]

mA=(({{2, 1, 3}, {1, 2, 1}, {2, 2, 2}}));
mB=(({{3, 2}, {4, 3}}));
mC=(({{-6, -1}, {5, 6}}));
mD=(({{3}, {4}}));
mE=(({{5}, {7}, {9}}));
mX=Array[X,{2,1}]
Solve[mB.mX+(({{7}, {6}}))==mD,Flatten[mX]]

mX=(({{-8}, {10}}))

11. Constructing a matrix given a rule for its ijth  term

mat=Table["Given Rule for i and j",{i,1,"Row number"},{j,1,"Column number"}];
mat//MatrixForm

mat=Table[2i-j+2,{i,1,2},{j,1,3}];
mat//MatrixForm

12. Matrices Multiplication Step by step with working out

nA=oA="the 1st matrix know";
nB=oB="the 2nd matrix know";
step1=MatrixForm[Inner[Inactive[Times],"the first matrix for multiplication e.g. nA","the first matrix for multiplication e.g. nB",Inactive[Plus]],TableSpacing->{3,3}]
step2=Activate[step1,Times]
Activate[step2]

nC=oC=(({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}));
step1=MatrixForm[Inner[Inactive[Times],nC,nC,Inactive[Plus]],TableSpacing->{3,3}]
step2=Activate[step1,Times]
Activate[step2]

MASTERSHEET
Copy/Paste Formulae for Module 2 Networks

>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.

MATHEMATICA COMMANDS FOR Module 2 Networks

1. Find all Hamiltonian Cycles

Clear[g]
g={"\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\"};
FindHamiltonianCycle[g,All]
GraphPlot[g,VertexLabeling->True]
FindHamiltonianCycle[g]
HighlightGraph[g,PathGraph[First[%]]]

Clear[g]
g={"A"\[UndirectedEdge]"B","A"\[UndirectedEdge]"D","B"\[UndirectedEdge]"C","B"\[UndirectedEdge]"E","D"\[UndirectedEdge]"G","D"\[UndirectedEdge]"E","E"\[UndirectedEdge]"G","E"\[UndirectedEdge]"H","E"\[UndirectedEdge]"F","C"\[UndirectedEdge]"F","H"\[UndirectedEdge]"I","F"\[UndirectedEdge]"I","G"\[UndirectedEdge]"H"};
FindHamiltonianCycle[g,All]
GraphPlot[g,VertexLabeling->True]
FindHamiltonianCycle[g]
HighlightGraph[g,PathGraph[First[%]]]

2. Find all Hamiltonian Path

Clear[g]
g={"\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\","\"\[UndirectedEdge]"\"};
FindHamiltonianPath[g,"\","\"]
GraphPlot[g,VertexLabeling->True]
FindHamiltonianPath[g,"\","\"]
HighlightGraph[g,PathGraph[FindHamiltonianPath[g,"\","\"]]]

List Hamiltonian path from vertex C to G

Clear[g]
g={"A"\[UndirectedEdge]"B","A"\[UndirectedEdge]"D","B"\[UndirectedEdge]"C","B"\[UndirectedEdge]"E","D"\[UndirectedEdge]"G","D"\[UndirectedEdge]"E","E"\[UndirectedEdge]"G","E"\[UndirectedEdge]"H","E"\[UndirectedEdge]"F","C"\[UndirectedEdge]"F","H"\[UndirectedEdge]"I","F"\[UndirectedEdge]"I","G"\[UndirectedEdge]"H"};
FindHamiltonianPath[g,"C","G"]
GraphPlot[g,VertexLabeling->True]
FindHamiltonianPath[g,"C","G"]
HighlightGraph[g,PathGraph[FindHamiltonianPath[g,"C","G"]]]

3. Minimal Spanning Tree: Prim’s Algorithm, Kruskal’s Algorithm

n="Number of vertices";
weightedEdges={{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"}};
Clear[adjM];
adjM[i_,j_]:=∞;
adjM[i_,j_]:=adjM[j,i]/;i>j;
weightedEdges/.{i_,j_,k_}:>(adjM[i,j]=k);
Array[adjM,{n,n}]//MatrixForm
Clear[g]
g=WeightedAdjacencyGraph[Array[adjM,{n,n}],VertexLabels->"Name",EdgeLabels->"EdgeWeight"]
FindSpanningTree[g]
HighlightGraph[g,%,GraphHighlightStyle->"Thick"]

n=7;
weightedEdges={{1,2,16},{1,5,17},{1,7,10},{2,3,24},{2,5,16},{5,4,17},{5,6,11},{5,7,12},{7,6,17},{6,4,15},{3,4,16}};
Clear[adjM];
adjM[i_,j_]:=∞;
adjM[i_,j_]:=adjM[j,i]/;i>j;
weightedEdges/.{i_,j_,k_}:>(adjM[i,j]=k);
Array[adjM,{n,n}]//MatrixForm
Clear[g]
g=WeightedAdjacencyGraph[Array[adjM,{n,n}],VertexLabels->"Name",EdgeLabels->"EdgeWeight"]
FindSpanningTree[g]
HighlightGraph[g,%,GraphHighlightStyle->"Thick"]

4. The Shortest Path: Dijkstra’s Algorithm

n="Number of vertices";
weightedEdges={{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"},{"two vertices number with weight of this edge, comma in between"}};
Clear[adjM];
adjM[i_,j_]:=∞;
adjM[i_,j_]:=adjM[j,i]/;i>j;
weightedEdges/.{i_,j_,k_}:>(adjM[i,j]=k);
Array[adjM,{n,n}]//MatrixForm
Clear[g]
g=WeightedAdjacencyGraph[Array[adjM,{n,n}],VertexLabels->"Name",EdgeLabels->"EdgeWeight"]
FindShortestPath[g,"Starting Vertex in number","Finishing Vertex in number"]
HighlightGraph[g,PathGraph[FindShortestPath[g,"Starting Vertex in number","Finishing Vertex in number"]]]

n=10;
weightedEdges={{1,2,17},{1,3,18},{1,4,15},{2,7,27},{2,5,18},{3,5,15},{3,6,10},{4,6,14},{4,10,29},{5,7,6},{5,9,12},{5,6,4},{6,9,17},{6,10,13},{7,8,15},{9,8,11},{9,10,3},{10,8,13}};
Clear[adjM];
adjM[i_,j_]:=∞;
adjM[i_,j_]:=adjM[j,i]/;i>j;
weightedEdges/.{i_,j_,k_}:>(adjM[i,j]=k);
Array[adjM,{n,n}]//MatrixForm
Clear[g]
g=WeightedAdjacencyGraph[Array[adjM,{n,n}],VertexLabels->"Name",EdgeLabels->"EdgeWeight"]
FindShortestPath[g,1,8]
HighlightGraph[g,PathGraph[FindShortestPath[g,1,8]]]

5. Matching & Allocation Problems: Hungarian Algorithm

Needs["Combinatorica`"]
g=Combinatorica`CompleteGraph["row number","column number"];
edgeWeights={{"Number on 1st column with comma, in between"},{"Number on 2nd column with comma, in between"},{"Number on 3rd column with comma, in between"},{"Number on 4th column with comma, in between"},{"Number on 5th column with comma, in between"}};
g1=Combinatorica`SetEdgeWeights[g,-Flatten[edgeWeights]];
Combinatorica`BipartiteMatchingAndCover[g1]
Extract[edgeWeights,First[%]/.x_/;x>"row number":>x-"row number"]
Total[%]

Needs["Combinatorica`"]
g=Combinatorica`CompleteGraph[4,4];
edgeWeights={{110,105,125,115},{95,82,78,90},{140,145,140,135},{80,80,75,85}};
g1=Combinatorica`SetEdgeWeights[g,-Flatten[edgeWeights]];
Combinatorica`BipartiteMatchingAndCover[g1]
Extract[edgeWeights,First[%]/.x_/;x>4:>x-4]
Total[%]

Answers Explain :           {1,6},{2,7},{3,8},{4,5} -->A-X, B-Y, C-Z, D-W                 398=Total Cost

6. Visualize Hamiltonian Cycles

a. Listing how many cycles from vertex 13 to vertex 17

g=PolyhedronData["Dodecahedron","Skeleton"];
hc=FindHamiltonianCycle[g,All];
{s,t}={13,17};
hps2t=Select[hc,MemberQ[(s|t)\[UndirectedEdge](s|t)]];
GraphicsGrid[Partition[Table[HighlightGraph[g,DeleteCases[p,(s|t)\[UndirectedEdge](s|t)],GraphHighlightStyle->"Thick"],{p,hps2t}],5]]

b. how one cycle traveling

dodecahedron=PolyhedronData["Dodecahedron","Skeleton"];
hcycle=First[FindHamiltonianCycle[dodecahedron]]
Animate[HighlightGraph[dodecahedron,PathGraph[hcycle[[1;;n]]],GraphHighlightStyle->"Thick"],{n,0,Length[hcycle],1}]