A) Create program code for function file “average” which takes as the input vector “v” and uses a for-loop to calculate the average of all the numbers in “v”. Hint: To determine the number of numbers (n) in the vector “v” you can use n = length (v) . Your code must begin with
function x = average (v)
B) b) Let T be a table with n = 100 rows and m = 100 columns. Write a program that, using pre-loop and if-testing, counts the number of columns in T that have an average value of less than 10.
HINT: You retrieve a copy of column number k in table T by typing t = T (:, k);
Task 3 (comparison and counting)
A) Create a program code for a function file “quantity” which takes as input one vector “v” and a number “t”, and returns the quantity of numbers in the vector “v” which is equal to the number “t” (Example: quantity t ([2 1 2 3 2], 2) = 3). Your code must begin with
function x = quantity (v, t)
B) b) Create program code for a function file “quantity A” which generalizes the function from 3a), takes as input a table (matrix) “A” and a number “t”, and returns the quantity of numbers in the table “A” which is equal to the number ” t ”. The code should start with
function x = quantityA (A, t)
HINT: You can determine the number of rows (n) and columns (m) in the table “A” with the code line [n, m] = size (A) ;.
B) Use the function you wrote in problem A) to simulate n = 100-coin toss. Write a program that counts the quantity of simulated coin tosses before the first “crown” occurs. Suggest a “reasonable” value for the case where since “crown” is not observed in the n coin tosses.