首页 > > 详细

MAST90045辅导、讲解c/c++编程语言、辅导data、c++留学生讲解解析Haskell程序|辅导留学生Prolog

MAST90045 - Assignment 1, 2020
The level of a dam
In this assignment we will model the changing level (or height) of water in a dam (Figure 1).
The minimum level is 0 and the maximum is hmax. The level increases when rain falls in the
catchment area and decreases as a result of evaporation and use. We will ignore any loss due
to leaks or seepage.
Height and volume
Volume Let A(h) be the cross-sectional area of the dam at height h.
h Area A(h)
Figure 1: An idealized dam.
The volume of water contained by the dam when it is filled to level h is
V (h) = Z h
0
A(u) du.
Write a function volume(h, hmax, ftn) that returns V (h) for h ∈ [0, hmax], where hmax is
hmax and ftn is a function of a single variable which is assumed to return A(h). For h < 0 or
h > hmax your function should return NA.
Give consideration to the accuracy of any numerical algorithms you use. Discuss your
choices.
Height If the current level of the dam is h and the volume of the dam changes by an amount
v, then the level of the dam becomes u = H(h, v) where u satisfies
V (u) = V (h) + v.
Note that if the right-hand side of this equation is > Vmax = V (hmax) or < 0, then this equation
has no solution. In this case we take u = hmax or u = 0, respectively.
Using a root-finding algorithm, write a function height(h, hmax, v, ftn) that returns
H(h, v), where hmax is hmax and ftn is a function of a single variable that is assumed to return
A(h). For h < 0 or h > hmax your function should return NA.
What is a suitable tolerance for the root-finding algorithm? Discuss your choice.
Figure 2: A schematic dam.
Test case Suppose that the dam is bowl-shaped with profile given by the equation y = πx2
.
That is, the dam has the shape obtained by rotating the curve y = πx2 about the y-axis
(Figure 2).
In this case it is easily seen that, for h ∈ [0, hmax] and v ∈ [−h
2/2, Vmax − h2/2],
A(h) = h;V (h) = h2/2; andH(h, v) = ph2 + 2v.
To test that your function height(h, hmax, v, ftn) works, define
A <- function(h) return(h)
then calculate height(h, hmax = 4, v, ftn = A) for the following values of h and v:
h −1 0.5 0.5 3.5 3.5 3.5 5
v 1 1 −1 1 2 −1 1
Check that your numerical results agree with the formula given above.
Tracking height over time
Suppose that h(t) is the level of the dam at the start of day t, and that v(t) is the volume
of rain falling into the catchment during day t, for t = 1, . . . , n. Also let α be the volume of
water taken from the dam for use per day, and let βA(h(t)) be the volume of water lost due to
evaporation during day t. Then the level of water in the dam at the start of day t + 1 is givenby
h(t + 1) = H(h(t), v(t) − α − βA(h(t))).
Further suppose that hmax = 3, α = 2, β = 0.1, and A(h) has the form
A(h) = (100h2 for 0 ≤ h ≤ 2;
400(h − 1) for 2 ≤ h ≤ 3.
The file catchment_b.txt gives v(t) for n = 100 consecutive days. Write a program that
reads this file then, for a given value of h(1), calculates h(2), . . . , h(n + 1). Plot your output for
the case h(1) = 1, as in the figure below.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!