Math 1483 - Quiz 4

<=/Solutions\=>

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

Problem 1

Suppose that we have two tanks, Tank A and Tank B, which are connected to allow water to transfer between them. Tank A contains 300 gallons of water in which 100 lbs of salt has been dissolved and Tank B contains 300 gallons of pure water (no salt initially in the tank). Fresh water is pumped into Tank A at the rate of 500 gallons per hour, and this mixture is pumped into Tank B from Tank A at a rate of 500 gallons per hour. The well mixed solution in Tank B is drained at a rate 500 gallons per hour. All brine mixtures are well-stirred. If we let A(t) be the amount of salt in Tank A at time t and be B(t) be the amount of salt in Tank B at time t, then we know (through other magical mathematical methods) the formulas for these functions are given by:
A(t) = 100 (e^(-(5/3)t)) and B(t) = (500/3)t (e^(-(5/3)t)).
Here A and B are measured in lbs, and t in hours.

A[t_]:=100 (E^(-(5/3)t));
B[t_]:=(500/3)t (E^(-(5/3)t));

Part 1

Evaluate A(0) and B(0) and compare those results to the situation described in the problem.  Do they agree?

A[0]

B[0]

Since there was 100 lbs of salt in Tank A at the start, and no salt in Tank B initially, the computations above agree with the setup.

Part 2

So no peeking ahead at part 3 here.  Clearly the functions which define A(t) and B(t) are somewhat complicated looking.  However, if you look at the problem and consider how the tanks are set up, how much salt should each tank have in it if this system is allowed to run for a very long time.  Note: you will NOT be marked off for an incorrect answer here, you just need to think about the problem and give a justification for what you think will happen.

Since only fresh water is being added to the system, and the mixture is leaving Tank B at the same rate as water is coming into Tank A, we should see the salt in both tanks go to zero over time.  Tank A should have its maximum amount of start right at the start, while Tank B will obtain its maximum at some positive time (since it starts with none, and then gets some salt from tank A).

Part 3

Plot A(t) and B(t) on the same graph, for the time range t=0 hours to t=10 hours.

Plot[{A[t],B[t]},{t,0,10},AxesLabel->{"time (min)", "salt (lbs)"},PlotLegends->{"Tank A", "Tank B"}, PlotRange->{{0,10},{0,110}}]

Part 4

Explain how the graphs given in part 3 agree (or disagree) with your intuition (part 2) about how much salt should be in each tank as time passes.  Be sure to include the initial state, the mixing of the tanks, and the amount of salt in the tanks after a long period of time has passed.

Tank A starts off with 100 lbs of salt in its 300 gallon tank, while Tank B starts off with no salt in its 300 gallon tank.  As they mix, salt will transfer from Tank A to Tank B since Tank B has less salt than Tank A.  At the same time, Tank A’s salinity is decreasing due to it taking on only fresh water.  And indeed, at some point, Tank B reaches a max salinity before it as it eventually is purged of all salt.

Part 5

Do the two tanks ever have the same salinity (lbs of salt/gallon)?

From the graph from part 3, the answer appears to be ‘yes’. We can use the NSolve command, and expect a t value close to t=0.5.  Indeed, we end up with t=0.6, which is 36 minutes.

NSolve[A[t]==B[t],t]

Part 6

Create a three-column table with the values of t, A(t), and B(t) for 0<= t <= 5 hours by increments of 15 minutes.  Be sure to express entries in the the columns corresponding to A(t) and B(t) in decimal form.

TableForm[Table[{t,N[A[t]],N[B[t]]},{t,0,5,0.25}] ,TableHeadings->{None,{"t hours","Salt in Tank A (lbs)", "Salt in Tank B (lbs)"}}]

Part 7

At what time does Tank B have a maximum amount of salt?

From the table from part 6, it appears that this occurs somewhere between 30 and 45 minutes. Note that this is also where the two tanks had the same amount of salt! (This makes sense if you think about it) Using the Maximize command, we see it happens at approximately 0.6 hours (36 minutes), with a value of 36.8 lbs of salt.

N[Maximize[{B[t],t>= 0},t]]

Part 8

On what time interval is the amount of salt in Tank B between 10 and 37 lbs?

We use the Reduce command, as shown below, and this gives us a time range of 0.0671 <= t <= 2.146 hours.

Reduce[10.0 <= B[t] <= 37.0,t,Reals]

Problem 2

The following table gives the price of gas (per gallon) for each week of the calendar year 2022.

({{Week of 2022,  Price/Gallon }, {1, $3.141}, {2, $3.164}, {3, $3.182}, {4, $3.199}, {5, $3.249}, {6, $3.330}, {7, $3.372}, {8, $3.410}, {9, $3.486}, {10, $3.963}, {11,  $4.180}, {12, $4.091}, {13, $4.078}, {14, $4.021}, {15, $3.943}, {16, $3.915}, {17, $3.959}, {18, $4.031}, {19, $4.161}, {20, $4.320}, {21, $4.410}, {22, $4.439}, {23, $4.702}, {24, $4.844}, {25, $4.798}, {26, $4.710}, {27, $4.619}, {28, $4.501}, {29, $4.350}, {30, $4.183}})

Data was gathered from: 
https://www.eia.gov/petroleum/gasdiesel/
To the right of the heading of “U.S. Regular Gasoline Prices (dollars per gallon) there is a link to the full data:
https://www.eia.gov/petroleum/gasdiesel/xls/pswrgvwall.xls
The “Data1” tab in this Excel spreadsheet is where the data can be found.

GasData =  {{1, 3.141},{2,3.164},{3,3.182},{4,3.199},{5,3.249},{6,3.330},{7,3.372},{8,3.410},{9,3.486},{10,3.963},{11,4.180},{12,4.091},{13,4.078},{14,4.021},{15,3.943},{16,3.915},{17,3.959},{18,4.031},{19,4.161},{20,4.320},{21,4.410},{22,4.439},{23,4.702},{24,4.844},{25,4.798},{26,4.710},{27,4.619},{28,4.501},{29,4.350},{30,4.183}};

Part 1

Plot the data.  Be sure to label your axes appropriately.

ListPlot[GasData, PlotStyle->Blue, PlotMarkers->{"▽",16}, AxesLabel->{"Week of 2022", "Price of Gas ($/gal)"}, Joined->False]

Part 2

Compute the rate of change for the weekly data. (Note this is for each pair of weeks, you should have 29 data points here corresponding to 30 weeks.)

ROCGasData  =Table[{StringForm[" `` to `` ",GasData  [[ i]][[1]],GasData  [[i+1]][[1]]],(GasData  [[i+1]][[2]]-GasData  [[i]][[2]])*1.0/(GasData  [[i+1]][[1]]-GasData  [[i]][[1]])},{i,1,Length[GasData  ]-1}];

TableForm[ROCGasData ,TableHeadings->{None,{"Change in Week","Change in Price/week ($/gal/week)"}}]

Part 3

On what week from the data set was there the greatest increase in gas price nationally?  Also, at what week was there the greatest decrease in gas prices nationally?

The maximum increase occurs from week 9 to week 10.
The maximum decrease occurs from week 29 to week 30.

Part 4

What is the average rate of change in the price per gallon of gas over the entire first 30 weeks of this year?

N[(GasData[[-1,2]]-GasData[[1,2]])/(GasData[[-1,1]]-GasData[[1,1]])]

N[(GasData[[30,2]]-GasData[[1,2]])/(GasData[[30,1]]-GasData[[1,1]])]

The average rate of change over the entire year to date (through July) is approximately an increase of 3.59 cents per gallon per week.

Part 5

When I was writing this exam, the date was July 30th, 2022 (week 30).  Thus, data for the work week starting August 1st, 2022 was not yet available (week 31).  Using the rate of change from week 29 to week 30, estimate the value of the price of gas for the next data point, August 1st, 2022, which is week 31.

The rate of change from week 29 to 30 is -0.167$/gallon/week.   So we take the value of of the price of gas for week 30, and subtract -0.167 from it:

GasData[[-1,2]]-0.167

So the price of gas is estimated to be $4.016/gallon

Part 6

Go to the website linked at the beginning of this problem, and compare the actual value with that of the estimate from part 5.  Explain in detail whether or not you think the estimate was a good estimate.

Price from the spreadsheet was $4.034, which is a wee bit off -- approximately 2 cents.  Due to the complexity involved with gas prices, assuming a linear relationship from one data point to another seems too simple.

Problem 3

Time for a “Let’s find something fun to do with Mathematica” problem.

Part 1

Have Mathematica create an interpolation function based on the data set GasData from Problem 2.  Look up “Interpolation” in the Help menu.

F = Interpolation[GasData]

Part 2

Evaluate the interpolating function from Part 1 at 31 (i.e. if you called the function from part 1 F, evaluate F[31.0]).  This will be the approximation to the price of gas/gallon for week 31 of 2022.

The result here is $4.017/gallon for week 22 of 2022.

F[31.0]

Part 3

Compare your result from part 2 to part 5 of the previous problem.  Do they agree? What can you conclude about the interpolating function with regards to average rates of change?

The two values are different, but not by much!  Using the linear rate of change, we ended up with a value of $4.016/gallon, while the interpolating function gives a value of $4.017/gallon.   Thus, we may conclude that the interpolating function does not simply use the average rate of change from day to day to evaluate the next value, but since the data appears pretty linear from week 24 to week 30, the interpolating function appears to be pretty close to linear in this region.