Question

In: Statistics and Probability

1. Write a code that constructs a matrix with 5 rows that contain the number 1...

1. Write a code that constructs a matrix with 5 rows that contain the number 1 up to 30. Your output matrix must be filled by the columns.

2. Create the vector_a containing five numeric values 5,7,8,9,10 and vector_b containing five numeric values 2,4,7,9,19. Write the output of the sum of vector_a and vector_b.

3. Create the vector_a containing five numeric values 5,7,8,9,10 and vector_b containing five numeric values 2,4,7,9,19. Write a code that combines vector_a and vector_b.

Solutions

Expert Solution

Ans 1)

Here we have to write a code that constructs a matrix with 5 rows that contain the number 1 up to 30 and output matrix must be filled by the columns.

 > m=matrix(1:30,byrow = FALSE,nrow=5) #it gives require matrix > m  [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 6 11 16 21 26 [2,] 2 7 12 17 22 27 [3,] 3 8 13 18 23 28 [4,] 4 9 14 19 24 29 [5,] 5 10 15 20 25 30

Ans 2)

 > a=c(5,7,8,9,10) > b=c(2,4,7,9,19) > output1=a+b #gives sum of two vector > output1 [1] 7 11 15 18 29

Ans3)

 > a=c(5,7,8,9,10) > b=c(2,4,7,9,19) > output2=c(a,b) #it combines the two vector > output2  [1] 5 7 8 9 10 2 4 7 9 19

I have also attached the R code of this question.

m=matrix(1:30,byrow = FALSE,nrow=5) #it gived the matrix of 1:30 fillesd by column
m

a=c(5,7,8,9,10)
b=c(2,4,7,9,19)
output1=a+b    #gives sum of two vector
output1

a=c(5,7,8,9,10)
b=c(2,4,7,9,19)
output2=c(a,b) #it combines the two vector
output2


Related Solutions

JAVA Write a program that prompts the user to enter a matrix number of rows and...
JAVA Write a program that prompts the user to enter a matrix number of rows and number of columns. In main method create 2D matrix based on the number of rows and columns input by the user; randomly fills the matrix with 0s and 1s and prints it. Create method sumColumns that takes only the matrix you created in main method and find the sum of each column with even index and prints it. Do not use global variables. Here...
Write code that will produce the following pyramid for a user designated number of rows (user...
Write code that will produce the following pyramid for a user designated number of rows (user input). 1 11 121 12321 1235321 (Based on Fibonacci numbers) *USE JAVA*
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write...
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write an algorithm to calculate the recursive Matrix multiplication (or write with pseudo code) 3. Find the time complexity of your pseudo code and analyze the differences
[PLEASE USE C++] Write a function to read values of a number of rows, number of...
[PLEASE USE C++] Write a function to read values of a number of rows, number of columns, 2 dimensional (2D) array elements and display the 2D array in a matrix form. Input 2 3 1 4 5 2 3 0 Where, First line of represents the number of rows. Second line of input represents the number of columns. Third line contains array elements of the 1st row and so on. Output 1 4 5 2 3 0 where There must...
Find the rook polynomial and an expression for the number of matchings of 5 men (rows)...
Find the rook polynomial and an expression for the number of matchings of 5 men (rows) with 5 women (columns) given the following forbidden pairings: (M1,W4), (M2,W2), (M3,W3), (M4,W2), (M4,W4), (M5,W1), (M5,W3), (M5,W45). Answer is 5! - 8x4! + 21x3! - 20x2!+ 6x1!, please explain how to get it, thanks.
2. Write a c++ program that takes from the user the ​number of courses​ and constructs...
2. Write a c++ program that takes from the user the ​number of courses​ and constructs 3 ​dynamic 1D arrays​ with size courses+1. Each array represents a student. Each cell in the array represents a student’s mark in a course. In the last cell of each 1D array you should calculate the average mark of that student. Then output the average mark of all students in each course. Delete any allocated memory. Example Number of courses : 4 50 60...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
Write a complete Java code that contain two classes. A GradeBook and a GradeBookTester. - The...
Write a complete Java code that contain two classes. A GradeBook and a GradeBookTester. - The GradeBook class contains the followings: - An array of grades (integer array) declared as a field. - A constructor that takes an integer value as parameter (len), and creates the grades array of size equals to len. - A method called fillArray that fills the grades array with random integers. Acceptable values are between 1 and 100 (inclusive) - A method called printStatistics that...
Consider the matrix P = I - X(XTX)-1X T . If matrix X has 4 rows...
Consider the matrix P = I - X(XTX)-1X T . If matrix X has 4 rows and 6 columns, what are the dimensions of matrix I? Prove that P is idempotent.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT