代写代考 Simpson’s rule

Simpson’s rule
For this question, you are required to write two R functions, to examine the accuracy of Simpson’s rule when calculating
P(a PowCoder代写 加微信 powcoder

P(a < X < b) = 16 as well as its approximation using Simpson's rule. For the exact value, you should use the pnorm() command in R. The arguments to your function should be: mu, the mean of the distribution (i.e. u in the formulae above); sigmasq, the variance (i.e. o2 in the formulae); a and b, the integration limits a and b; and n, the value of n to use in Simpson's rule. The default value of n should be 100. Your function should return a list containing components p. approx, the Simpson approximation to the probability; p. exact, the value obtained using pnorm () ; n, the value of n; and p. error, the difference p.approx-p. exact. You may use the dorm () command to calculate the normal probability density function if you wish. Your second function should be called simpsonTest (). Its purpose is to evaluate the error of the Simpson approximation to P(a < X ≤ b) for different values of n, and to estimate the value of a as described in the introduction above. The arguments to this second function should be: mu, sigmasq, a, b, and n. grid. These all have the same interpretation as the corresponding arguments to normprob () , except for n. grid which should be a vector of values for n. Your SimpsonTest () function should use normprob () to obtain a vector of approximation errors for each value of n in n. grid. It should then use 1m () to regress the log of the absolute approximation error against the log of n. grid, and take the estimated slope of the regression as an estimate of -a. The function should return a list containing components n. grid (the value of n. grid), abs. error (a vector containing the absolute values of the approximation errors) and alpha (the estimate of a). Introduction In Workshop 3, you looked at the trapezium rule for integrating a function over a finite range. Simpson's rule is an alternative to the trapezium rule, which is more accurate. Specifically, for finite integration limits a < b, Simpson's rule approximates where n is an even number, h = (b-a)/n and x; = a + j(b-a)/n. Let en denote the absolute value of the approximation error when Simpson's rule is used to evaluate an integral. It can be shown that en is roughly proportional to n'9 for some exponent a, so that log(en) is roughly equal to K - alog(n) for some constant K. The value of a can be established theoretically; but in situations where the exact value of the integral is known, it can also be estimated by evaluating the Simpson approximation for several values of n, calculating the absolute error en each time, and then regressing log(en) against log(n): the slope of the regression line is an estimate of -a. For this question, you are required to write two R functions, to examine the accuracy of Simpson's rule when calculating P(a < Xs b) where X ~ N(4,02) and -o < a < 6 < 00. Your first function should be called normprob (), and should calculate the exact value of as well as its approximation using Simpson's rule. For the exact value, you should use the pnorm0 command in R. The arguments to your function should be: mu, the mean of the distribution (i.e. u in the formulae above); sigmasq, the variance (i.e. o 2 in the formulae); a and b, the integration limits a and b; and n, the value of n to use in Simpson's rule. The default value of n should be 100. Your function should return a list containing components p. approx, the Simpson approximation to the probability; p. exact, the value obtained using pnorm (); n, the value of n; and p. error, the difference p. approx-p. exact. You may use the dorm () command to calculate the normal probability density function if you wish. Your second function should be called SimpsonTest (). Its purpose is to evaluate the error of the Simpson approximation 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com