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 January of 2021 as measured by the Accuweather site:

https://www.accuweather.com/en/us/durant/74701/january-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 LowTempsJan, similarly for high tems -- HighTempsJan

LowTempsJan = {{1,36},{2,34},{3,30},{4,32},{5,36},{6,43},{7,40},{8,25},{9,26},{10,32},{11,30},{12,28},{13,27},{14,32},{15,37},{16,30},{17,34},{18,32},{19,46},{20,43},{21,43},{22,45},{23,43},{24,46},{25,46},{26,32},{27,30},{28,25},{29,32},{30,45},{31,37}};
HighTempsJan = {{1,41},{2,54},{3,63},{4,64},{5,51},{6,52},{7,47},{8,45},{9,47},{10,39},{11,50},{12,54},{13,63},{14,61},{15,50},{16,57},{17,59},{18,66},{19,57},{20,46},{21,55},{22,61},{23,54},{24,55},{25,66},{26,54},{27,48},{28,52},{29,61},{30,72},{31,55}};

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[{LowTempsJan ,HighTempsJan}, 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[LowTempsJan[[All,2]]]]

N[Median[LowTempsJan[[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[HighTempsJan[[All,2]]]]

N[Median[HighTempsJan[[All,2]]]]

Part 5

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

DiffSet = Table[{HighTempsJan[[i]][[1]],HighTempsJan[[i]][[2]]-LowTempsJan[[i]][[2]]},{i,1,Length[HighTempsJan]}]

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[{LowTempsJan ,HighTempsJan,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 January 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 36 F on January 13th, and the least change in daily temperature was 3 F on January 20th.

Max[DiffSet[[All,2]]]

Position[DiffSet[[All,2]],36]

DiffSet[[13]]

Min[DiffSet[[All,2]]]

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

DiffSet[[20]]

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 fiber, 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 fiber, 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 ounce serving of walnuts:

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

This is simply TotCal(4,18,4,2) .

TotCal[4,18,4,2]

Part 3

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

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

3.5*TotCal[4,18,4,2]

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 2.68 servings allowed for a 500 calorie snack.

NSolve[500 ==s*TotCal[4,18,4,2],s]

Problem 3

The following table gives the total number of people vaccinated in Oklahoma:

({{Day (in January), Total People Vaccinated }, {12, 109045}, {13, 118786}, {14, 160035}, {15, 173162}, {19, 209687}, {20, 217690}, {21, 230902}, {22, 247954}, {23, 263315}, {24, 279283}, {25, 282679}})

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 = {{12, 109045},{13,118786},{14,160035},{15,173162},{19,209687},{20,217690},{21,230902},{22,247954},{23,263315},{24,279283},{25,282679}}

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

Part 2

You will notice that data is missing for the dates January 16th-18th.  Use the data from January 15th and 19th to extrapolate the total number of people vaccinated on each of the missing dates.

We need to use entries 4 and 5, which correspond to the dates of the 15th and 19th.  On average, there is are 9131.25 people vaccinated per day, if we extrapolate.  We will round that down.

AvgVaccineDaily = N[(PeopleVacData[[5]][[2]]-PeopleVacData[[4]][[2]])/(PeopleVacData[[5]][[1]]-PeopleVacData[[4]][[1]])]

MissingData = {{16,PeopleVacData[[4]][[2]]+AvgVaccineDaily},{17,PeopleVacData[[4]][[2]]+2*AvgVaccineDaily},{18,PeopleVacData[[4]][[2]]+3*AvgVaccineDaily}}

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 January", "People Vaccinated"}, Joined->False];

Show[VaccDataPlot,MissingVaccDataPlot]

Part 4

Estimate the total number of people vaccinated on January 26th using the data points from January 24th and 25th.  (Note: the actual value for January 26th is 284799).

We simply compute the slope using the last two points, then add that to the total from January 25th.  This gives 286075.

LastVaccineDaily = N[(PeopleVacData[[-1]][[2]]-PeopleVacData[[-2]][[2]])/(PeopleVacData[[-1]][[1]]-PeopleVacData[[-2]][[1]])]

PeopleVacData[[-1]][[2]]+%

Part 5

The actual value for the total number of people vaccinated up through January 26th is 284799.  Was your answer from Part 4 an overestimate or underestimate?

It was an overestimate, by 1276.  We predicted there should have been an additional 3396 additional people vaccinated, thus our estimate was significantly off.

286075-284799

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,1000}];

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 10000 primes is 3682913.

Total[PrimeList]