Download Exercise 1 Exercise 2 Exercise 3 Exercise 4

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

History of the function concept wikipedia , lookup

Determinant wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Matrix calculus wikipedia , lookup

Transcript
Advanced Statistics
1
Lab 3 - Basics in R, part 3
Systems modelling and data analysis
2016/2017
Exercise 1
1. Create a 100x100 matrix with the vector of natural numbers, whose values start
at 1. Save the matrix as m.
2. Multiply by 2 all the elements of the matrix, where the value is greater than 5000.
Save the changes in the matrix.
3. Calculate the sum of 6 elements in 60,61,62 column and row 5.6. Use the sum
function.
Exercise 2
1. Create a matrix of 50 rows and 50 columns. Assign a value of 1 to all elements
of the first 25 rows. Assign a value of 2 for all elements of the last 25 rows. Save
as a matrix m.
2. Divide all the elements of 15th column by 2. Save the changes in the matrix.
3. See the sum of the elements of 13th to 19th column and from 11th to 17th row
(sum function).
Exercise 3
1. Create a matrix of 25 columns and 50 rows from the vector of natural numbers,
whose values start at 1. Save the matrix as m.
2. If one of the matrix values is equal to one of the first 5 elements of the Fibonacci
sequence (1,2,3,5,8), assign a NA value to this elements of the matrix.
3. If any of the values in the row is set to NA, remove this row from the matrix.
Show the average of all items (mean function).
Exercise 4
1. Create a matrix of 50 columns and 25 rows from the vector of natural numbers,
whose values start at 1. Save the matrix as m.
2. If one of the matrix values is equal to one of the first 4 elements of the Fibonacci
sequence (1,2,3,5), assign a NA value to this elements of the matrix.
3. If any of the values in the row is set to NA, remove this row from the matrix.
Show the sum of all items (sum function).
Advanced Statistics
2
Exercise 5
1. Create a matrix with 60 rows and 30 the columns from vector of even numbers
(2, 4, 6, ...). Save the matrix as m1.
2. Create m2 matrix composed of nine elements of the matrix m1: the columns 3 to
5, rows 5 to 7.
3. Multiply matrix m2 with matrix m2, then calculate the sum of the elements of
the resulting matrix (use the sum function).
Exercise 6
1. Create a matrix with 60 columns and 30 rows from vector of odd numbers (1, 3,
5, ...). Save the matrix as m1.
2. Create m2 matrix composed of 9 elements of the matrix m1: the columns 5 to 7,
rows from 3 to 5.
3. Multiply matrix m2 with matrix m2, then calculate the average of the elements
of the resulting matrix (use the mean function).
Exercise 7
1. Create a matrix with 60 columns and 60 rows from vector comprising a multiplies
of 5 (5, 10, 15, ...). Save the matrix as m1.
2. Create m2 matrix composed of 9 elements of the matrix m1: the columns 15 to
17, rows from 13 to 15.
3. Multiply matrix m2 with matrix m2, then calculate the sum of the elements of
the resulting matrix (use the sum function).
Exercise 8
1. Create a matrix with 30 columns and 30 rows from vector comprising a successive
powers of 2 (2, 4, 8, 16, ...). Save the matrix as m1.
2. Create m2 matrix composed of 9 elements of the matrix m1: the columns 13 to
15, rows from 15 to 17.
3. Multiply matrix m2 with matrix m2, then calculate the average of the elements
of the resulting matrix (use the mean function).
Exercise 9
1. Create a sum function that takes any number of arguments (including numeric or
text arguments).
2. Convert the arguments to numbers.
Advanced Statistics
3
3. Add all the arguments using the for loop. If any of entered values can not be
converted to the number, skip this argument during the addition. Use the if
structure.
4. Call created function by using the arguments: sum(1: 9, "test", 1: 9)
Exercise 10
1. Create an average function that takes any number of arguments (including numeric or text arguments).
2. Convert the arguments to numbers.
3. Calculate the mean value of all the arguments using the for loop. If any of
entered values can not be converted to the number, skip this argument during the
calculation. Use the if structure.
4. Call created function by using the arguments: average(1: 9, "test", 1: 9)
Exercise 11
1. Create a factorial function, which takes one argument.
2. Convert the argument to a natural number.
3. If the value can not be converted to a natural number, assign a NA value.
4. Write a function that will calculate the factorial for a given argument (n!).
5. Calculate factorial(10).
Exercise 12
1. Create a maximum function which takes any number of arguments (including
numeric or text arguments).
2. Convert the arguments to numbers.
3. Find an argument with the maximum value using a for loop, and the if construction. If any of the entered values can not be converted to the number, skip this
argument during scanning.
4. Call the function by using the arguments: maximum(“test”, 1:9, “test”).
Exercise 13
1. Create a minimum function which takes any number of arguments (including
numeric or text arguments).
2. Convert the arguments to numbers.
Advanced Statistics
4
3. Find an argument with the minimum value using a for loop, and the if construction. If any of the entered values can not be converted to the number, skip this
argument during scanning.
4. Call the function by using the arguments: minimum(“test”, 1:9, “test”).
Exercise 14
1. Create an areeven function which takes any number of arguments (including numeric or text arguments).
2. Convert the arguments to numbers.
3. Check that all arguments are even using for loop and if structure. If any of the
entered values can not be converted to the number, skip this argument during
scanning.
4. Call the function by using the arguments: areeven(2, 4, 6, 8, “test”, 10).
Exercise 15
1. Create an areodd function which takes any number of arguments (including numeric or text arguments).
2. Convert the arguments to numbers.
3. Check that all arguments are odd using for loop and if structure. If any of the
entered values can not be converted to the number, skip this argument during
scanning.
4. Call the function by using the arguments: areodd(1, 3, 5, 7, “test”, 9).
Exercise 16
1. Create a fibonacci function, which takes one argument.
2. Convert the argument to a natural number. If the value can not be converted to
a natural number, assign a NA value.
3. List the n terms of the Fibonacci sequence, where n is defined as a parameter of
the function.
4. Call the function by using the argument: fibonacci(10).