Question
What is the R code and result in Rstudio

1. The following data gives, for each amount by which an elastic band is stretched over the end of a ruler, the distance that the band moved when released: stretch 46 54 48 50 44 4 52 distance 148 182 173166 109 141 166 Create a data frame in R with two columns that contain stretch and dis tance respectively. Plot the distance versus the stretch using plot) function What trend do you observe? 2. a. In R, define the following matrices -(1 )and b-GP) b. Find the elementwise multiplication of a and b, as well as the matrix multiplication of a and b c. Find matrix c, such that ac b and ca b. d. Explicitly report the eigenvalues and eigenvectors of a and b. 3. What is the difference between a vector and a list in R? What about the difference between a matrix and a dataframe in R? 4. Without using R, provide the output from the following command in R: c = 1 : 16; d = array(c, dim = c(2, 4, 2)); d[1 , 2, 2]
5. Explain the connection between r and y, where norm(.5);y pnorm (0) 6. Toss a fair coin 10 times. Find the probability of getting exactly 5 heads a) using the formula of Binomial pmf b) using Binomial density function dbinom; c) using Binomial cumulative probability function pbinom; 7. a) In R, define the following matrices V2/2 -V2/2 ,c = V2/2 ) , and d = (1/3 b) In R, check that diag(eigen(a)Svalues) will lead to matrix b, and eigen(a)Svectors w lead to matrix c. c) In R, use t(c) to get the transpose of matrix c, where the columns of matrix c become the rows of the transpose of matrix c d) Check that matrix a can be decomposed into ctimes b times t(c), where times means matrix multiplication e) Check that diag(1/eigen(a)Svalues) wil lead to matrix d. Furthermore, check that c times d times t(c) become the inverse of matrix a.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

Store the given data into stretch and distance vector.

stretch = c(46,54,48,50,44,42,52)
distance = c(148,182,173,166,109,141,166)

Store distance and stretch vector in a dataframe "df"

df = data.frame(stretch,distance)

You can now type df in R studio to get the contents of dataframe df.

> df
stretch distance
1 46 148
2 54 182
3 48 173
4 50 166
5 44 109
6 42 141
7 52 166

Plot the stretch and distance plot with the below command.

plot(df$stretch,df$distance, pch = 16, xlab = "stretch", ylab = "distance")

8 3 42 46 48 50 52 54 stretch

The plot shows there is a linear relationship between stretch and distance with exception of one point (Stretch = 44, distance = 109)

2.

a.

Define the matrices a and b with the below commands in R studio.

a = matrix(data = c(2, 1, 1, 2), byrow = TRUE, nrow = 2)
b = matrix(data = c(1, 0, 0, 1), byrow = TRUE, nrow = 2)

b.

Element wise multiplication is done by the command a * b

The output is,

> a * b
[,1] [,2]
[1,] 2 0
[2,] 0 2

Matrix multiplication is done by the command a %*% b

The output is,

> a %*% b
[,1] [,2]
[1,] 2 1
[2,] 1 2

c.

ac = b => c = a-1b

We can use solve() function in R to get the inverse of a matrix. Run the command c = solve(a) %*% b

The output is shown below.

> c = solve(a) %*% b
> c
[,1] [,2]
[1,] 0.6666667 -0.3333333
[2,] -0.3333333 0.6666667

ca = b => c = ba-1

Run the command c = b %*% solve(a)

The output is shown below.

> c = b %*% solve(a)
> c
[,1] [,2]
[1,] 0.6666667 -0.3333333
[2,] -0.3333333 0.6666667

We will get the same value of c in both the outputs.

d.

Eigen values and vectors for a matrix is calculated by the eigen() command in R. The output of the command eigen(a) and eigen(b) is shown below.

> eigen(a)
$values
[1] 3 1

$vectors
[,1] [,2]
[1,] 0.7071068 -0.7071068
[2,] 0.7071068 0.7071068

> eigen(b)
$values
[1] 1 1

$vectors
[,1] [,2]
[1,] 0 -1
[2,] 1 0

Eigen values of a are 3, 1

Eigen vectors of a are (0.7071068, -0.7071068) and (0.7071068, 0.7071068)

Eigen values of b are 1, 1

Eigen vectors of b are (0, -1) and (1, 0)

Add a comment
Know the answer?
Add Answer to:
What is the R code and result in Rstudio 1. The following data gives, for each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Consider the matrix (a) By hand, find the eigenvalues and eigenvectors of A. Please obtain...

    2. Consider the matrix (a) By hand, find the eigenvalues and eigenvectors of A. Please obtain eigenvectors of unit length. (b) Using the eigen function in R, verify your answers to part (a). (c) Use R to show that A is diagonalizable; that is, there exists a matrix of eigenvectors X and a diagonal matrix of eigenvalues D such that A XDX-1. The code below should help. eig <-eigen(A) #obtains the eigendecomposition and stores in the object "eig" X <-eigSvectors...

  • What is the code and result in Rstudio or R 1. Suppose we have a random...

    What is the code and result in Rstudio or R 1. Suppose we have a random sample 1.12, 0.44, -1.49, 0.02, 0.81, -1.34,1.34, 0.51,-0.12, 0.97. (a). Use two methods to find the sample mean (b). Use two methods to find the sample variance. (c). Find the sample standard deviation. 2. We can use function rt(n 100, df 2) to generate a random sample from a t-distribution with two degrees of freedom. The sample size is n 100. (a). Generate a...

  • Matrix Algebra 3. indicated sums and products are defined. Mark each statement True of False. Justify each The foll...

    Matrix Algebra 3. indicated sums and products are defined. Mark each statement True of False. Justify each The following questions concern arbitrary matrices A, B, and C for which the answer (a) If A and B are 2 x 2 matrices with columns ai, a2 and bi, b2, respectively, thern 101 a2b2] (b) Each column of AB is a linear combination of the columns of B using weights from the corresponding column of A. (c) AB + AC-A(B +C (d)...

  • Can you help me with this question please? For the code, please do it on MATLAB. Thanks

    Can you help me with this question please? For the code, please do it on MATLAB. Thanks 7. Bonus [3+3+4pts] Before answering this question, read the Google page rank article on Pi- azza in the 'General Resources' section. The Google page rank algorithm has a lot to do with the eigenvector corresponding to the largest eigenvalue of a so-called stochastic matrix, which describes the links between websites.2 Stochastic matrices have non-negative entries and each column sums to1, and one can...

  • What is the R code and result in Rstudio or R 1. Define a character vector...

    What is the R code and result in Rstudio or R 1. Define a character vector in R as follows: y - c("a, "bc", "def") a. Report the output of the following function: length(y);y"a;y"b" b. nchar(x) takes a character vector x as an argument and returns a vector whose elements contain the sizes of the corresponding elements of x. Report the output of nchar(y) 2. Define a numeric vector in R as follows: z=c(3,7,1,2) a. Report the output of the...

  • on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A,...

    on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A, of matrix A is accesser (3) Correcting an entry is easy to (4) Any submatrix of Ais obtained by d row wise. Rows are separated by semicolons and columns are separated by spaces ner A l 23:45 6. B and hit the return/enter kry matrix A is accessed as A Enter and hit the returnerter key an entry is easy through indesine Enter 19...

  • Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1. A square matrix...

    Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1. A square matrix is called right stochastic matrix if its rows are probability vectors; a square matrix is called a left stochastic matrix if its columns are probability vectors; and a square matrix is called a doubly stochastic matrix if both the rows and the columns are probability vectors. **Write a MATLAB function function [S1,S2,P]=stochastic(A) which accepts a square matrix A...

  • Write in C code What to do Write a function with the following signature: float* matrix...

    Write in C code What to do Write a function with the following signature: float* matrix multiplication(float* left, float* right, int rows, int shared, int columns); The first two arguments are two pointers to the beginning of two matrices with the dimensions (rows,shared) and (shared, columns) correspondingly. The remaining arguments specify these dimensions. The return value will return a pointer to the very beginning of the result matrix. That said, you need to provide the space for the result matrix...

  • Please code in C++. link to continue the code is this below or you can make...

    Please code in C++. link to continue the code is this below or you can make your own code if you wish(fix any mistakes if you think there are any in it): cpp.sh/3qcekv 3. Submit a header file (project3.h), a definition file (project3.cpp), a main file (main.cpp), and a makefile to compile them together. Make sure to run the command make and produce an application file and include it with your submission. For this project, you are required to create...

  • the last pic is number 14 please answer it as a,b,c,d as well. thanks 1. If...

    the last pic is number 14 please answer it as a,b,c,d as well. thanks 1. If A is diagonalizable then A is diagonalizable. a) True b) The statement is incomplete c) False d) None of the above 2. In every vector space the vector (-1)u is equal to? a) -U b) All of the above c) None of the above d) u 3. The set of vectors {} is linearly dependent for a) k = 3 b) k = 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT