Home Page > > Details

The Hong Kong Polytechnic University

Department of Applied Mathematics

AMA3632 Programming for Data Science

Assignment 1

Instructions:

1. Due Date: 1 Nov 2019 at 5:30pm.

2. Full marks of this assignment is 6 marks.

3. Type your codes and outputs in the word document or a R notebook file. Give comments on

your codes. Handwriting codes are NOT accepted.

4. Submission Method: Please submit ONLINE in Blackboard AND submit a HARD COPY

assignment DURING THE LECTURE before the deadline. LATE assignments could NOT

be accepted by the Blackboard system.

Questions:

1. Consider the following very simple genetic model. A population consists of equal numbers of two

sexes: male and female. At each generation men and women are paired at random, and each pair

produces exactly two offspring, one male and one female. We are interested in the distribution

of height from one generation to the next.

(a) Assume that the heights of the both male and female in the first generation are randomly

chosen from a normal distribution with mean 160 cm and variance of 400 cm2

. Use commands,

dataframe, rnorm, to generate a data frame called “pop” for the first generation.

(b) Suppose that the height of both children is just the average of the height of their parents.

Write a function to generate a data frame containing the height of males and/or females for

next generation. You may use sample command to permutate the male and female height

in random. For calculation of mean height for the offspring, you may use apply and mean

commands.

(c) Use the function from part (b) to generate nine generations and then use the lattice library

to obtain histogram of male heights for nine generations. The last plot of heights phenomen

of the male heights is called regression to the mean.

2. For f : R → R, the NewtonRaphson algorithm uses a sequence of linear approximations to f

to find a root. What happens if we use quadratic approximations instead? Suppose that xn

is our current approximation to f; then a quadratic approximation to f at xn is given by the

second-order Taylor expansion:

f(x) ≈ gn(x) = f(xn) + (x − xn)f

Let xn + 1 be the solution of gn(x) = 0 that is closest to xn, assuming a solution exists. If

gn(x) = 0 has no solution, then let xn + 1 be the point at which gn attains either its minimum

or maximum. Figure 1 illustrates the two cases.

Figure 1: The iterative root-finding scheme of the Newton-Raphson algorithm based on the secondorder

Taylor expansion.

Implement this algorithm in R and use it to find the fixed points of the following functions:

(a) cos(x) − x using x0 = 1, 3, 6.

(b) log(x) − exp(−x) using x0 = 2.

(c) x

3 − x − 3 using x0 = 0.

(d) x

3 − 7x

2 + 14x − 8 using x0 = 1.1, 1.2, ..., 1.9.

(e) log(x) exp(−x) using x0 = 2.

For your implementation, assume that you are given a function ftn(x) that returns the vector

(f(x), f′

(x), f′′(x)). Given xn, if you rewrite gn as gn(x) = a2x

2 + a1x + a0 then you can use the

1 − 4a2a0)/2a2 to find the roots of gn and thus xn+1. If gn has no roots then

the min/max occurs at the point g′n(x) = 0.

Contact Us(Ghostwriter Service)

- QQ：99515681
- WeChat：codinghelp2
- Email：99515681@qq.com
- Work Time：8:00-23:00

- Ghostwriter Math223 Assignment,R Cours... 2020-05-28
- Ghostwriter Kxo151 Assignment,Help Wit... 2020-05-28
- Math 160 Assignmenthelp With ,Data Cou... 2020-05-28
- Help With Csci 3120 Assignment,Program... 2020-05-28
- St2020 Course Assignmenthelp With ,Sta... 2020-05-28
- Com1005 Assignmentghostwriter ,Ai Tech... 2020-05-28
- Ghostwriter Sit216 Assignment,Python P... 2020-05-28
- Ghostwriter Artificial Course Assignme... 2020-05-27
- Comp Sci 3306 Assignmentghostwriter ,P... 2020-05-27
- Data Assignmentghostwriter ,Help With ... 2020-05-27
- Csci 3120 Assignmenthelp With ,C++ Pro... 2020-05-26
- Ghostwriter Algorithms Assignment,Data... 2020-05-26
- Data Science Assignmentghostwriter ,C+... 2020-05-26
- Data Course Assignmentghostwriter ,C++... 2020-05-26
- Ghostwriter R Assignment,Help With Dat... 2020-05-25
- Cosc473 Assignmenthelp With ,Systems A... 2020-05-25
- Data Assignmenthelp With ,R Programmin... 2020-05-25
- Comp 250 Assignment 3 2020-05-24
- Macm 316 – Computing Assignment 7 2020-05-24
- Sta457 Assignment 2020-05-24

Contact Us - Email：99515681@qq.com WeChat：codinghelp2

© 2014 www.asgnhelp.com

Programming Assignment Help！