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")
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)
What is the R code and result in Rstudio 1. The following data gives, for each...
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 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 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
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 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, 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 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 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 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 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...