Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Engineering Mathematics Expert

Q1. Give R code using the function rep() to create the following vectors?

(i) 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

(ii) 1 2 2 2 2 2 3 3 4 4 5

Q2. Give R code using the function seq() to produce a vector of twenty increasing equally spaced points between -2 and 3.

Q3. Give R code to evaluate the following, without using loops

1852_figure.png

Q4. Provide R code which uses a loop to generate samples of size 100 from t-distributions with degrees of freedom equal to 1, 2, 4, 8, 16, 32 and stores them in the columns of a 100 x 6 matrix. Create a histogram of each sample, together with a normal probability plot complete with a line to assess how straight the Q-Q plot is. The plots should be arranged in a 2 x 6 array on a single graph sheet, with the histograms on the top row and the Q-Q plots in the bottom row. Each plot should have a title with an indication of the distribution (including degrees of freedom) used to generate the data.

Q5. Carefully describe what is accomplished by the following piece of R code, commenting on each line of the code:

x <- seq(-5, 5, by = 0.1)

y <- 3 + 1.2 * x + rnorm(length(x) , mean=0,sd=2)

par (pty=" s" )

plot(x, y, pch=1)

title(main="Plot of Response vs. Explanatory")

fit <- lm(y ~ x)

abline(fit)

summary(fit)

par(pty="m", mfrow=c(2, 2))

plot (fit)

Q6. Assume that Y is a numeric matrix with n rows and m columns. Describe in detail what is accomplished by the following R code:

Ym <- rep(0, m)

Ys <- rep(0, m)

for (j in (1:m)) {

Ym[j] <- mean (Y [, j] )

Ys[j] <- sd(Y[,j])

for (i in (1:n) ) {

Y[i,j]<- (Y[i,j] - Ym[j] ) /Ys[j]

}

}

How can you compute Ym and Ys and perform the same transformation on Y in a quicker and more transparent way?

Use the function scale () in conjunction with the function apply () to perform the same transformation on Y in a single line of code (without calculating the values of Ym and Ys).

Q7. Suppose that f(x) is a function defined for all x ∈  (0, 1) . Also, suppose that you do not know how to compute 01 f(x)dx. One way to estimate the integral by simulation is as follows:

(i) randomly draw n points x in (0, 1);

(ii) generate the vector y such that y[i]=f (x[i]);

(iii) estimate the integral using the sample mean of y

I^ = y-.

Write a R function sim.integ() which takes as arguments the function f and returns the above estimates I^ of 01f(x)dx.

(b) Use your function to evaluate

01x2sin(x) + tan(x) dx.

for n = 100, 1000, 10000, 100000.

(c) Calculate the integral using R's integrate() function. [The exact value of the integral is -2 + 2 * sin(1) + cos(1) - log(cos(1)) = 0.83887.]

Q8. Let yt be a sequence of random variables that follows the moving average model of order 1:

yt = εt + bεt-1       t = 2, ..., N

where εt are i.i.d. N(0, σ2) and b is a known constant in the interval [-1, 1]. To define y1, we set ε0 = 0. According to this model, yt is equal to a noise term εt plus (or minus, depending on the sign of b) some fraction of the noise term εt-1 at the previous time.

Write an R function MA1() that takes as arguments the final time N and the parameters b and σ and generates a sequence yt from the model above, and plot four generated sequences in a 2 x 2 display.

The function should return a list with three components: b, sigma and a vector y containing the generated sequence. The function should check that N and o are positive and that b lies in the interval [-1, 1] and return an error if not.

Q9. Suppose that f(x) is a monotone function (i.e. strictly increasing or strictly decreasing) defined on an open interval of the real line and with a unique root xr satisfying f(xr) = 0. The root xr can be found numerically using an iterative method known as the regula falsi or secant method. Given two values xi and xi-1, the method determines the secant line, i.e. the line that goes through the points (xi-1, f(xi-1)) and (xi, f (xi)). The next iterate xi+1 is the value where the secant line cuts the x-axis, which is easily shown to be given by the following equation

xi+1 = xi - f(xi)( xi - xi-1/f(xi)-f(xi-1)).

Write an R function regulafalsi 0 to implement the secant method. The arguments of regulafalsi () should include a function f() to providing the definition of f(x), and two values x0 and x1 to start the iterations.

Use the function regulafalsi() to solve the equation

x1/2 + 3 log x = 5 x > 0.

numerically, starting at x = 1. Compare with the result of using the function uniroot() to find a solution in the interval (1,5).

Engineering Mathematics, Engineering

  • Category:- Engineering Mathematics
  • Reference No.:- M91963575

Have any Question?


Related Questions in Engineering Mathematics

Show all your work not just the answerswhen you multiply 21

(SHOW ALL YOUR WORK, not just the answers) When you multiply: 21 x 68 you most likely do: 8x1 + 8x20 + 60x1 + 60x20 = 1, 428 So, there are 4 multiplications and then 3 additions. How long would it take a computer to do t ...

1 this problem concerns of the proof of the np-completeness

(1) This problem concerns of the proof of the NP-completeness of 300L a) Convert the formula F into a 300L graph b) Find a solution for the 300L instance of F and verify that it is a solution for F F = (Z 1 V Z 2 ) ^ (z ...

Question a signal starts at point x as it travels to point

Question : A signal starts at point X. As it travels to point Y, it loses 8 dB. At point Y, the signal is boosted by 10 bB. As the signal travels to point Z, it loses 7 dB. The dB strength of the signal at point Z is -5 ...

Assignment - introduction to math programmingdirections

Assignment - Introduction to Math Programming Directions - Formulate a linear programming model for the following description. Include definitions of decision variables, Objective function, and constraints. Augment your ...

Clculus assignment -q1 find the total differential of w

CALCULUS ASSIGNMENT - Q1. Find the total differential of w = x 3 yz + xy + z + 3 at (x, y, z) = (1, 2, 3). Q2. Find the value of the double integral ∫∫ R (6x + 2y 2 )dA where R = {(x, y)| - 2 ≤ y ≤ 1, y 2 ≤ x ≤ 2 - y. Q3 ...

All these questions should be answered in matlab 1 generate

All these questions should be answered in MATLAB !!! 1. Generate a set of 3 random patterns of dimension 12 where each value is +1 or -1.(3 random 12*12 matrix) 2. Create a 12-unit Hopfield network (a 12x12 matrix) from ...

Assignment - lp problemsthe data for all the problems in

Assignment - LP problems The data for all the problems in this HW are included in the LP_problems_xlsx spreadsheet Problem 1: Cash Planning A startup investment project needs money to cover its cash flow needs. At the en ...

I have these questions for a homework assignment and have

I have these questions for a homework assignment and have to show work. This works with MIPS coding language and is the class Introduction to Computer Architecture. 1. Find the 2's complement representation (in 32-bit he ...

Question suppose g is an undirected connected weighted

Question : Suppose G is an undirected, connected, weighted graph such that the edges in G have distinct edge weights. Show that the minimum spanning tree for G is unique.

Problem 1given a sequence xn for 0lenle3 where x0 1 x1 1

Problem # 1: Given a sequence x(n) for 0≤n≤3, where x(0) = 1, x(1) = 1, x(2) = -1, and x(3) = 0, compute its DFT X(k). (Use DFT formula, don't use MATLAB function) Use inverse DFT and apply it on the Fourier components X ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As