Vous êtes sur la page 1sur 2

COMS 1005, Fall 2010

Assignment 6
Due: 10/19, class time

Submission: Courseworks (A single file for each question uni1234.Assignment6.zip that contains folders
Question1, Question2, … for each question that contains functions *.m, required by the question; for
each subsection, include diary1a.txt diary1b.txt within the relevant question’s folder …. that
demonstrate running your code and textual answers where required)

Functions should return error messages if need be.

Functions should follow the specification of input and output arguments.

Functions should be well-documented.

The next two questions involve a particular way in which programming is helpful in any data analysis
that needs to figure out statistics.

1. You want to evaluate the chance that a random point (x,y) in the square -1≤x≤1, -1≤y≤1 is in the
unit-circle around the origin.
a. Write a function quarter_pi that receives a parameter many and evaluates this
chance by choosing many random such points and reporting the fraction of them within
the circle.
b. Write a function accuracy that receives integer parameters many and
many_times_over and evaluates the accuracy of quarter_pi by calling
quarter_pi(many) many_times_over times, and reporting the square root
of the sum of all squared differences between estimates of π/4 and a quarter of
MatLab’s constant pi. Report the accuracy of quarter_pi(100) ,
quarter_pi(10000), quarter_pi(1000000)using values of
many_times_over you see fit, and explain why. Bonus: show accuracy of < 10-5.

2. You are studying the social structure of volleyball teams. You ask the players in each of the ten
6-person teams in the league who is friends with whom among the teammates. You find that in
all 10 teams there is either a triplet of friends (a,b are friends; b,c are friends; a,c are friends), or
a triplet of non-friends (a,b are friends; b,c are friends; a,c are friends). You want to know how
unusual is its.
a. Write a function random_team that gets an input parameter probability
parameter and returns a 6x6 binary matrix describing random friendships between team
members, such that each pair of individuals has an independent chance probability
to be friends. Note that friendship is symmetric (a is a friend of b if and only if b is a
friend of a) and non-reflexive (you are not a friend of yourself).
b. Write a function triple_team that returns whether the input team has a triplet of
friends or of non-friends.
c. Write a function random_league that gets an input parameter probability and
returns a 3-d matrix of 10 teams.
d. Write a function triple_in_each_team_in_league that returns whether each
team in the input league has a triplet of friends/no-friends
e. Write a function sim_teams that gets two input parameters, probability and
many, that simulates many leagues with friendship probability probability .
Execute and report your findings.

3. Write a function kth_freq_word_of_len that gets as parameters a text (in a cell array of
strings), a rank k, and a length, and finds the k-th most frequent word of length k in the given
text. The function should work on long texts, specifically, the one provided in
WarAndPeace.mat .

4. This question is supposed to help grade assignment 6, by verifying that the required folders and
files exist.
a. Write a function assignment_dir_exists that receives an input a uni of a student
(as a string) and a question number. The function should check if the current folder
includes a folder for this assignment by the input student (returning 0 otherwise), and
whether this folder includes (return 1) a folder for the input question, or not (return 0).
Report an error if the uni is not legal (2-3 characters, then a number of 1-4 digits), or if
the question number is not 1-4.
b. Write a function assignment_dir that receives the same input, and returns three
lists (cell arrays of strings) of the filenames that are, respectively, ok (are supposed to be
there, and indeed are), missing (are supposed to be there, but are not) or extra (are not
supposed to be there). Report an error if any of the relevant folders do not exist.

Vous aimerez peut-être aussi