Question

Solve following using Program R studio. Please show code and results. Thank you. Consider the following...

Solve following using Program R studio. Please show code and results. Thank you.

Consider the following vectors:

?1 = (2, −1, 0)

?2 = (−1, 2, −1)

?3 = (0, −1, 2)

1. Use cbind to construct 3× 3 matrix which called ?.

2. Construct a matrix ? using the diagonal elements from point (3).

3. Calculate the upper triangular matrix using matrix ?.

4. Use outer function to divide each element in ?1 by the vector ?2.

5. Use outer function to add each element in ?1 to the vector ?2.

6. Use outer function to give the results of “each element in ?1 minus the elements of the vector ?2”.

Homework Answers

Answer #1

R code with results:

> x1<-c(2, −1, 0)
> x2<-c(−1, 2, −1)
> x3<-c(0, −1, 2)
> m<-cbind(x1,x2,x3)
> m
x1 x2 x3
[1,] 2 -1 0
[2,] -1 2 -1
[3,] 0 -1 2

> u<-diag(diag(m),nrow = 3,ncol = 3)
> u
[,1] [,2] [,3]
[1,] 2 0 0
[2,] 0 2 0
[3,] 0 0 2

> x<-as.vector(c(-1,0,-1))
> x
[1] -1 0 -1
> y <- matrix(0, nrow=3, ncol=3)
> y[upper.tri(y)] <-x
> y
[,1] [,2] [,3]
[1,] 0 -1 0
[2,] 0 0 -1
[3,] 0 0 0

> z<-outer(x1,x2,FUN = "/")
> z
[,1] [,2] [,3]
[1,] -2 1.0 -2
[2,] 1 -0.5 1
[3,] 0 0.0 0

> w<-outer(x1,x2,FUN="+")
> w
[,1] [,2] [,3]
[1,] 1 4 1
[2,] -2 1 -2
[3,] -1 2 -1

> v<-outer(x1,x2,FUN="-")
> v
[,1] [,2] [,3]
[1,] 3 0 3
[2,] 0 -3 0
[3,] 1 -2 1

>

Know the answer?
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
Similar Questions
let us create a variable for a row vector a = [1, 4, 1, 3, 2,...
let us create a variable for a row vector a = [1, 4, 1, 3, 2, 5, 0] and calculate the mean value of its elements using the Matlab function ‘mean’ and store this value in variable aMean. Fig. 1 gives the Matlab code to do this. a = [1, 4, 1, 3, 2, 5, 0]; aMean = mean(a); Figure 1: Matlab code – row vector and mean of its elements. Let us now construct a row vector b that...
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input...
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input matrix A as its only input argument. Matrix A is a 3x3 matrix of random integers between 1 and 4 2. Produces and output matrix B as its only output argument. Matrix B will also be a 3x3 matrix. 3. Calculates the elements of matrix B such that: a. the values of B along the diagonal are equal to the respective elements in A...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No Input/No Output Write a function that has no input and no outputs. This function will simply display some text when it is called. (this is my code, are there suggestions for improvements?) function Display() disp('some text') end 2. 1 Input/No Outputs Write a function with one input and no outputs. This function will simply display a variable that is provided as an input argument....
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with MSTest. My program is below. I just need screen shots of the unit test code in Visual Studio 2019 with MSTest. Please and thank you. using System; namespace SelectionSortAlgorithm { public class SelectionSort { public static void Main(string[] args) { int[] dataSet = new int[5] { 2, 99, 27, 68, 3 }; // 5 element array initialized int n = 5; // variable declar...
For part b and c could you please show r code to solve the problem. Thank...
For part b and c could you please show r code to solve the problem. Thank you 2. 34 petri dishes are prepared with a growth medium. 16 are randomly selected and treated with antibiotic A. The other 18 are treated with antibiotic B. Each dish is inoculated with a bacteria. Several hours later, the diameter of the bacteria colony in each dish is measured in mm, with these results: A: 8.59, 7.80, 4.11, 8.68, 8.08, 7.86, 6.97, 8.21, 1.72,...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
FALL_19_ASSIGN-2 Solve the following problems in your command window after turning your ‘diary’ on. Then submit...
FALL_19_ASSIGN-2 Solve the following problems in your command window after turning your ‘diary’ on. Then submit your command window outputs. Please make sure that your code prints: Name, ID, Seat #, Assign_2 in the first line of your command window. 1-22: Type one line in command window so that it displays answer to the following question: A total of 4217 eggs have to be packed in boxes that can hold 36 eggs each. How many eggs will remain unpacked if...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
Microsoft Visual Studio in C#: I have this code and need to loop through each element...
Microsoft Visual Studio in C#: I have this code and need to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object. This is the 2nd time to ask this question; it should have all the detail you need to help me. It is a piece of a project and I am trying not to give you the whole project. How do I use a foreach loop to loop through...