讲解:AMA3632、Data Science、R、RMatlab|Python

The Hong Kong Polytechnic UniversityDepartment of Applied MathematicsAMA3632 Programming for Data ScienceAssignment 1Instructions: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 onyour codes. Handwriting codes are NOT accepted.4. Submission Method: Please submit ONLINE in Blackboard AND submit a HARD COPYassignment DURING THE LECTURE before the deadline. LATE assignments could NOTbe accepted by the Blackboard system.Questions:1. Consider the following very simple genetic model. A population consists of equal numbers of twosexes: male and female. At each generation men and women are paired at random, and each pairproduces exactly two offspring, one male and one female. We are interested in the distributionof height from one generation to the next.(a) Assume that the heights of the both male and female in the first generation are randomlychosen 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 fornext generation. You may use sample command to permutate the male and female heightin random. For calculation of mean height for the offspring, you may use apply and meancommands.(c) Use tAMA3632代做、代写Data Science、代写R编程he function from part (b) to generate nine generations and then use the lattice libraryto obtain histogram of male heights for nine generations. The last plot of heights phenomenof the male heights is called regression to the mean.2. For f : R → R, the NewtonRaphson algorithm uses a sequence of linear approximations to fto find a root. What happens if we use quadratic approximations instead? Suppose that xnis our current approximation to f; then a quadratic approximation to f at xn is given by thesecond-order Taylor expansion:f(x) ≈ gn(x) = f(xn) + (x − xn)fLet xn + 1 be the solution of gn(x) = 0 that is closest to xn, assuming a solution exists. Ifgn(x) = 0 has no solution, then let xn + 1 be the point at which gn attains either its minimumor maximum. Figure 1 illustrates the two cases.Figure 1: The iterative root-finding scheme of the Newton-Raphson algorithm based on the secondorderTaylor 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) x3 − x − 3 using x0 = 0.(d) x3 − 7x2 + 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) = a2x2 + a1x + a0 then you can use the1 − 4a2a0)/2a2 to find the roots of gn and thus xn+1. If gn has no roots thenthe min/max occurs at the point g′n(x) = 0.转自:http://www.3daixie.com/contents/11/3444.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • 贵妃醉酒戏书笺, 李白吟诗颂百篇。 手捧墨香辞赋发, 晚归牧笛伴炊烟。
    诗人萧入铭阅读 821评论 1 8
  • 2019-02-24 日精进打卡 姓名:彭新 部门岗位:进口部 【日精进打卡第329天】 【知~学习】 听书 一、...
    新新小阅读 33评论 0 0
  • 169公分67公斤那个叫做Messi的雄狮决定战斗! 欧洲冠军联赛冠军,西甲联赛冠军,西班牙国王杯冠军,欧洲超级杯...
    孤勇QAQ阅读 372评论 0 1