Notice: Undefined index: url in /var/www/html/wp-content/themes/orfeo/functions.php on line 432

(b) [5 marks] Write a function calcAreaGen that generalises the calcArea function in part (a):

• The calcAreaGen function have additional numeric arguments s, u, v and w, which corresponds to the parameters of the cubic polynomial f(x)= s(x − u)(x − v)(x − w).

• The calcAreaGen function calculates and returns the area between the x-axis and f(x)= s(x − u)(x − v)(x − w).

(c) [2 marks] Use the function calcAreaGen created in part (b) to calculate the area between the x-axis and f(x)=0.25(x+5)(x+1.5)(x−0.5),usingthesequence a = x0 = −5.5 < −5.4 < … < 0.9 < 1.0= xN = b to deﬁne the subintervals. In this case the subintervals all have the same length of 0.1.

IMPORTANT: You must use loops for this question, otherwise a heavy penalty will be applied.

Question 3: Finding a set of unique paths

[20 marks]

A path in two dimensional space is a line that has a starting point at (x,y)-coordinates of (xo,yo) and an end point at (xe,ye). In this question, you can assume that xo ≤ xe.

Figure 2: Examples of paths in two dimensional space. (a) A path with a starting point at (xo,yo)=(0.5,2) and end point at (xe,ye)=(1.5,2.5). (b) Two overlapping paths. The red path has a starting point at (0.5,2) and end point at (1.2,2.35), while the blue path has starting and end points at (1.0,2.25) and (1.6,2.55) respectively. (c) The path formed by merging together the red and blue paths in (b).

(a) [5 marks] Write a function getYIntAndSlope, which calculates the y-intercept and the slope of a path. Thus, the function will have the following features.

Arguments:

• xo is a numeric object representing the x-coordinate of the starting point (xo) of a path,

• yo is a numeric object representing the y-coordinate of the starting point (yo) of a path, • xe is a numeric object representing the x-coordinate of the end point (xe) of a path, and

• ye is a numeric object representing the y-coordinate of the end point (ye) of a path.

Computations:

• This function calculates the y-intercept and the slope of the path given by the starting and end points as speciﬁed by the arguments.

Returns:

• A numeric vector, where its ﬁrst element is the y-intercept and the second is the slope. Note: the y-intercept and slope in the vector must be in that order.

(b) [15 marks] Write a function getPathSet that extracts the unique set of paths. Speciﬁcally, it would have the following features.

Arguments:

(1) pathMat is a numeric matrix with four columns. Each row speciﬁes a path in two dimensional space, while the columns specify the following information.

• column 1: the x-coordinate of the starting point (xo),

• column 2: the y-coordinate of the starting point (yo), • column 3: the x-coordinate of the end point (xe), and

• column 4: the y-coordinate of the end point (ye).

For example, if the path in Figure 2 (a) is in pathMat, then the row corresponding to that path should look like 0.5 2.0 1.5 2.5.

Computation:

• This function extracts the unique paths in pathMat.

• Overlapping paths are replaced with a single path formed by merging those paths together. For example, in Figure 2 (b) there are two overlapping paths in red and blue. They should be merged into one path (purple) as in panel (c). The purple path should be added to the output matrix,

while the red and blue paths are excluded.

Hint: Use the getYIntAndSlope function in part (a) as part of the computation.

Return:

• A numeric matrix with four columns.

– The rows represent the set of unique paths generated in Computation.

– The columns of the vector are the (x,y)-coordinates of the starting and end points of those paths, and the order of the columns are the same as in the argument pathMat.

IMPORTANT:

• You must use loop(s) and conditional statements for part (b) of this question, otherwise a heavy penalty will be applied.

• You will only obtain marks for part (b) of this question if your function produces a matrix with the correct set of paths.

EasyDue™ 支持PayPal, AliPay, WechatPay, Taobao等各种付款方式!

E-mail: easydue@outlook.com  微信:easydue

EasyDue™是一个服务全球中国留学生的专业代写公司