Math 1483 - Quiz 2

<=/Solutions\=>

Remember, ALT+7 gives a new text cell, be sure to explain your answers, if needed!

Problem 1

Your task for this problem will involve visualizing weather data

Part 1

Examine the weather data for Durant, OK over the month of February of 2021 (the great cold storm of the century happened during this month!!!) as measured by the Accuweather site:

https://www.accuweather.com/en/us/durant/74701/february-weather/335176?year=2021

Store the data in two separate data sets:
(1) The first data set being ordered pairs consisting of the day of the month and the day’s high temperature.
(2) The second data set being ordered pairs consisting of the day of the month and the day’s low temperature.
Give each data set an appropriate name.

The low temps will be stored in the variable LowTempsFeb, similarly for high tems -- HighTempsFeb

LowTempsFeb = {{1,32},{2,36},{3,36},{4,37},{5,32},{6,37},{7,32},{8,32},{9,28},{10,27},{11,23},{12,21},{13,19},{14,9},{15,5},{16,0},{17,18},{18,19},{19,14},{20,21},{21,37},{22,32},{23,36},{24,50},{25,41},{26,45},{27,46},{28,50}};
HighTempsFeb = {{1,59},{2,63},{3,70},{4,63},{5,63},{6,43},{7,54},{8,52},{9,32},{10,30},{11,27},{12,25},{13,30},{14,19},{15,18},{16,23},{17,30},{18,32},{19,43},{20,54},{21,68},{22,68},{23,79},{24,70},{25,55},{26,59},{27,59},{28,68}};

Part 2

Create a plot of each of the data sets.  Your plot should include the following:
(1) Make sure the symbols for each set is distinct.
(2) Colour the high temp data set red.
(3) Colour the low temp data set blue.
(4) Add legends for each data set.
(5) Add the appropriate labels to both axes.
(6) Connect the points in each data set by lines. (Hint: This is an option in the ListPlot command)

HiLoTempPlot = ListPlot[{LowTempsFeb ,HighTempsFeb}, PlotLegends->{"Low Temps","High Temps"}, PlotStyle->{Blue, Red}, PlotMarkers->{{"▽",16},{"✶",12}}, AxesLabel->{"Day of January", "Temp (F)"}, Joined->{True, True}]

Part 3

Compute the average and median for the daily low temp data set.

We use the Mean and Median commands here.  The mean is 35.39, and the median is 34.

N[Mean[LowTempsFeb[[All,2]]]]

N[Median[LowTempsFeb[[All,2]]]]

Part 4

Compute the average and median for the daily high temp data set.

Same idea here, mean is 54.81, median is 54.

N[Mean[HighTempsFeb[[All,2]]]]

N[Median[HighTempsFeb[[All,2]]]]

Part 5

Construct a data set which is the difference between the daily high temp and daily low temp

DiffSet = Table[{HighTempsFeb[[i]][[1]],HighTempsFeb[[i]][[2]]-LowTempsFeb[[i]][[2]]},{i,1,Length[HighTempsFeb]}]

Part 6

Plot the difference data set along with the two data sets from Part 2, be sure to use a different colour for the new data set, and add a plot legend for it.

ListPlot[{LowTempsFeb ,HighTempsFeb,DiffSet}, PlotLegends->{"Low Temps","High Temps","Difference in Temp"}, PlotStyle->{Blue, Red, Cyan}, PlotMarkers->{{"▽",16},{"✶",12},{"◻",16}}, AxesLabel->{"Day of January", "Temp (F)"}, Joined->{True, True, True}]

Part 7

On what days in February were there the largest and smallest changes in daily temperature?

We can use the Max command, and the Position command to locate where the max value occurs.  Similarly, we can use the Min command.  The greatest change in temperature was 43 F on February 23rd, and the least change in daily temperature was 3 F on February 10th.

Max[DiffSet[[All,2]]]

Position[DiffSet[[All,2]],43]

DiffSet[[23]]

Min[DiffSet[[All,2]]]

Position[DiffSet[[All,2]],%]

DiffSet[[10]]

Problem 2

A common formula used for counting calories of a food consumed is given by:

TotCal(P,F,C,D) = 4P+9F+4(C-D)

Where T is the total number of calories, P is the number of grams of protein, F is the number of grams of fat, C the total number of grams carbohydrate, and D the number of grams of dietary fiber.

We define the function with the following command.  Be sure to execute it!

TotCal[P_,F_,C_,D_]:=4*P+9*F+4*(C-D)

Part 1

Explain what TotCal(14,8,7,5) represents, and then evaluate it.

This represents the total net calories from a food source with 14 grams of protein, 8 grams of fat, 7 total grams of carbohydrates with 5 of them being from dietary fiber.

TotCal[14,8,7,5]

Part 2

The following is the nutritional information for a 1 cup serving of pecans:


Express the total number of calories from a 1 cup serving of pecans in function notation using the function TotCal(P,F,C,D) .

This is simply TotCal(10,78,15,10) .

TotCal[10,78,15,10]

Part 3

Using your answer from Part 2, and being honest with yourself that you could not simply eat 1 cup of pecans, compute the total number of calories in a 2.5 cup serving.

As we can see, the total is 651 calories since we take the 1 ounce value from Part 2, and multiply it by 2.5.

2.5*TotCal[10,78,15,10]

Part 4

How many servings can you have if you are allowed a 500 calorie snack?

Here we simply use the equation # servings * TotCal(P,F,C,D)  = 500 calories.  We see that using the NSolve command below results in 0.66 servings allowed for a 500 calorie snack.  Not very much eh?

NSolve[500 ==s*TotCal[10,78,15,10],s]

Problem 3

The following table gives the total number of people fully vaccinated in Oklahoma over a window of time in April of 2021:

({{Day (in April),  People Fully Vaccinated }, {1, 1243871}, {2, 1268778}, {3, 1290295}, {4, 1307768}, {5, 1315073}, {6, 1318146}, {7, 1335798}, {8, 1351773}, {9, 1368221}, {10, 1386123}, {14, 1417964}, {15, 1428544}, {16, 1438343}, {17, 1447491}})

Go here for covid state data: https://github.com/owid/covid-19-data/tree/master/public/data/vaccinations

Part 1

Plot the data given in the table above.  Be sure to label your axes appropriately.

PeopleVacData = {{1, 1243871},{2,1268778},{3,1290295},{4,1307768},{5,1315073},{6,1318146},{7,1335798},{8,1351773},{9,1368221},{10,1386123},{14,1417964},{15,1428544},{16,1438343},{17,1447491}}

VaccDataPlot = ListPlot[PeopleVacData, PlotLegends->{"People Vaccinated"}, PlotStyle->Blue, PlotMarkers->{"✶",12}, AxesLabel->{"Day of April", "People Fully Vaccinated"}, Joined->False]

Part 2

You will notice that data is missing for the dates April 11th-13th.  Use the data from April 10th and 14th to extrapolate the total number of people vaccinated on each of the missing dates.

We need to use entries 10 and 11, which correspond to the dates of the 10th and 14th.  On average, there is are 7690.25 people obtaining full vaccination status per day, if we extrapolate.  We will round that down.

PeopleVacData[[10]]

PeopleVacData[[11]]

AvgVaccineDaily = N[(PeopleVacData[[11]][[2]]-PeopleVacData[[10]][[2]])/(PeopleVacData[[11]][[1]]-PeopleVacData[[10]][[1]])]

MissingData = N[{{11,PeopleVacData[[10]][[2]]+AvgVaccineDaily},{12,PeopleVacData[[10]][[2]]+2*AvgVaccineDaily},{13,PeopleVacData[[10]][[2]]+3*AvgVaccineDaily}},12]

Part 3

Plot the missing data you computed along with the data from part 1.  Be sure to use a different symbol and colour for the missing data.

MissingVaccDataPlot = ListPlot[MissingData, PlotLegends->{"Missing Data"}, PlotStyle->Red, PlotMarkers->{"▽",12}, AxesLabel->{"Day of April", "People Fully Vaccinated"}, Joined->False];

Show[VaccDataPlot,MissingVaccDataPlot]

Part 4

The number of people fully vaccinated at the end of the days April 11th, 12th, and 13th were 1,402,339, 1,410,306, and 1,414,279, respectively.  Compute the difference between the actual values and the values you estimated in Part 2.  Explain your results.

We simply compute the differences we found using the MissingData variable.

{{MissingData[[1,2]],1402339},{MissingData[[2,2]],1410306},{MissingData[[3,2]],1414279}}

{MissingData[[1,2]]-1402339,MissingData[[2,2]]-1410306,MissingData[[3,2]]-1414279}

So it appears that the linear approximations were an underestimate for all three days.

Part 5

The differences you computed in Part 4 give you the amount the approximations were off, however they lack context.  A better way to look at these differences is in terms of relative differences.  A relative difference is is the difference divided by the correct value, which gives us a percentage.  For instance, if a value is known to be 142, and we estimate it to be 128, the difference is:

142-128

While the relative difference is

(142-128)/142.0

This tells us that the relative difference is 0.985, or approximately a 9.85% deviation. 

Compute the relative differences between your estimates and the actual data from Part 4.  How far off, relatively, are your estimates?

{(MissingData[[1,2]]-1402339)/1402339.0,(MissingData[[2,2]]-1410306)/1410306.0,(MissingData[[3,2]]-1414279)/1414279.0}

The relative differences are all off by less than a single percentage, for the 11th and 12th, it was 0.6%, and for the 13th it was 0.3%, which are all very small.

Part 6

Plot the correct data values which were given in Part 4 for April 11th-13th, along with the two data sets you plotted in Part 3.  Once again, be sure to use a new symbol and colour!

CorrectData = N[{{11,1402339},{12,1410306},{13,1414279}}]

CorrectMissingVaccDataPlot = ListPlot[MissingData, PlotLegends->{"Correct Missing Data"}, PlotStyle->Black, PlotMarkers->{"◻",12}, AxesLabel->{"Day of April", "People Fully Vaccinated"}, Joined->False];

Show[VaccDataPlot,MissingVaccDataPlot,CorrectMissingVaccDataPlot]

Problem 4

Using the Graphics command to draw a blue circle of radius 4 centered at (1, 1), a green triangle with vertices at (-1, 2), (2, 1), and (1, -2) on the same graph, and your name in magenta coloured text at the point (1, 2).

Graphics[{Thick,Blue,Circle[{1,1},4],Green,Line[{{-1,2},{2,1},{1,-2},{-1,2}}], Magenta, Text["Karl",{1,2}]}]

Problem 5

Remember that a number is prime if and only if it is divisible only by itself and by 1.  Mathematica has a built in command to determine if a number is prime, it is called PrimeQ.  Also, if a number is not prime, we call it composite, and the FactorInteger command can tell us what its factors are!

PrimeQ[21847109]

PrimeQ[21847111]

FactorInteger[21847111]

11*13*152777

Part 1

Create a list which contains the first 10,000 prime numbers, storing it in the variable named PrimeList.

We use the Table command to create the list, and the Prime command to compute the ith prime.

PrimeList = Table[Prime[i],{i,1,10000}];

PrimeList[[1]]

PrimeList[[100]]

PrimeList[[1000]]

Part 2

Sum the entries of PrimeList

Here we use the Total command, which sums the entries.  The sum of the first 10,000 primes is 496,165,411.

Total[PrimeList]