CS 99

Summer 2002: Lab 6                                                                               07.18

Matrices

 

1.    Objectives

Completing all tasks in this assignment will help you:

First skim, then carefully read the entire assignment before starting any tasks.

2.    Matrix assignments
Write a program that prompts the user for integer values M and N, then creates an M x N array called A of random numbers between 0 and 1 (not inclusive).  Move through the array, element by element, and set any value that is less than 1/pi to 0 and any value that is greater or equal to 1/pi to 1.

Save your M-file as
RandArray.m.  Be sure to show your original and final matrices.

3.    Course scores
A matrix contains the marks of a group of students.  The three columns of the matrix represent scores for the quiz, assignments, and exam respectively. All marks are out of 100, and each row represents one student. The test is worth 20%, the assignments 20% and the exam 60%. If a student gets 50 in the test, 60 in the assignments and 40 in the exam, their final mark will be 46.  Write a program that, given a matrix of scores, outputs a vector of final marks.

Test your program on a
20 x 3 matrix of random scores in the range 0 to 100.  Be sure to include the matrix as well as the vector of marks.

Save your M-file as
Scores.m.

4.    Dominating permutations
A dominating permutation is a collection of integers such that no integer has two immediate neighbors both of which are larger than it (the first and last numbers have only one neighbor).

Part A.
Write a program called
Dominate.m that determines if a given array is a dominating permutation.  Run your program on a 1-D array of random integers, whose size n is determined by the user; let the range of the random integers be [1, n].   Be sure to include the results of your experiment in your printout.

Part B.*
Use the results of your last program and the built-in MATLAB function
perms (help perms) to answer the following interesting question: of all the permutations of the numbers {1, 2, 3, 4}, how many are dominating?  how about the numbers {1, 2, 3, 4, 5}?  is the fraction equal to the theoretical result 2n-1/(n!) ?  Hint: to find the value of n! use function prod on any row of perms(1:n).

Save your M-File for this part as
DominateFact.m.

 *Optional

5.     Submitting Your Work
Type your name (and your partner’s name if you have one), student ID, and the date at the top of each M-file.  Print each file and sign them along with your partner.  Give the signed documents to the teaching assistant at the end of the lab session.