Home Teaching Research CV Timetable

Prev: P4 Next: P6
Back to week 9 page: Link



# P5 Programming Problem Instruction

📗 Enter your ID (the wisc email ID without @wisc.edu) here: and click (or hit enter key)
📗 The due date is Apr 6, late submissions within a week will be accepted without penalty, but please submit a regrade request form: Link.
📗 The same ID should generate the same set of questions. Your answers are not saved when you refresh the page or close the browser.
📗 To input your answers, you could (1) copy and paste your answers to the text boxes for individual questions, or (2) print your answers to text files and load them into the text boxes for individual questions, or (3) print all your outputs to a single text file and load it using the button at the bottom of the page under the Submission section. More details at the bottom of page W1.
📗 Please report any bugs on Piazza.

# Warning: please enter your ID before you start!



# Questions 1 to 2 Instruction

📗 Create a vector of Fibonacci numbers and a lower triangular matrix with Binomial coefficients.
📗 Fibonacci numbers have the property that \(F_{i} = F_{i-1} + F_{i-2}\) with \(F_{1} = F_{2} = 1\). Details see: Wikipedia.
📗 Binomial coefficients have the property that \(B_{i,j} = B_{i-1,j} + B_{i-1,j-1}\) with \(B_{i,1} = B_{i,i} = 1\) for each \(i = 1, 2, 3, ...\). Details see: .
📗 Note: you can use the tril function in MATLAB to get the lower triangular part of a matrix, details see: Doc
📗 Note: you are allowed to use permutation formula, but it is highly recommended that you do not use it, and use the above recurrence relation instead, for this question.

# Question 1

📗 [1 point] Create a vector of ??? Fibonacci numbers: ???.
📗 Answer:


# Question 2

📗 [1 point] Create a lower triangular matrix with ??? rows of Binomial coefficients: ???.
📗 Answer:


# Questions 3 to 6 Instruction

📗 Simulate loaded dice throw and stop until you get \(n\) "\(x\)"s. Create a matrix with 2 rows, the first row contains random numbers between 0 and 1, and the second row contains the numbers on the dice corresponding to the random numbers in the first row based on the inverse transform method. Use the value of \(n\) and \(x\) and probabilities specified in each question. Enter the matrix you created.
📗 Inverse transform sampling samples a random variable with cumulative density by finding \(x = F^{-1}\left(u\right)\) where \(u\) is a uniform random number between 0 and 1. Details see: Wikipedia.
📗 Aside: the only possible fair dice (having faces with the same shape and size) have four, six, eight, twelve or twenty faces. Details see: Wikipedia.

# Question 3

📗 [1 point] Create the matrix based on the probabilities and stop until you get the ???st "???". The last column should correspond to the last "???".
📗 Answer:


# Question 4

📗 [1 point] Create the matrix based on the probabilities and stop until you get the ???th "???". The last column should correspond to the last "???".
📗 Answer:


# Question 5

📗 [1 point] Create the matrix based on the probabilities and stop until you get the ???st "???". The last column should correspond to the last "???".
📗 Answer:


# Question 6

📗 [1 point] Create the matrix based on the probabilities and stop until you get the ???th "???". The last column should correspond to the last "???".
📗 Answer:


# Questions 7 to 9 Instruction

📗 Create a vector representing a deck of \(n\) cards. Use the value \(1\) to represent a card facing up and \(0\) to represent a card facing down. Start with all cards facing up and you flip all cards at positions that are divisible by some integers. For example, flipping positions that are divisible by \(2\) means flipping the \(2\)nd, \(4\)th, \(6\)th, ... cards, and flipping positions that are divisible by \(3\) means flipping the \(3\)rd, \(6\)th, \(9\)th, ... cards. Use the size of the deck and the list of integer divisors specified in each question. Enter the vector representing the cards after you finish flipping the cards in the text box below each question.
📗 Note: a positive number has an odd number of divisors if and only if it is a perfect square. Details see: Wikipedia.

# Questions 7

📗 [1 point] Create the vector representing ??? cards (initially facing up) after flipping all cards at positions that are divisible by ???.
📗 Answer:


# Questions 8

📗 [1 point] Create the vector representing ??? cards (initially facing up) after flipping all cards at positions that are divisible by ???. Clarification: this means flipping the cards divisible by ??? first, then flipping the cards divisible by ??? next, then flipping the cards divisible by ???, and so on.
📗 Answer:


# Questions 9

📗 [1 point] Create the vector representing ??? cards (initially facing up) after flipping all cards at positions that are divisible by ???. Clarification: this means flipping the cards divisible by ??? first, then flipping the cards divisible by ??? next, then flipping the cards divisible by ???, and so on.
📗 Answer:


# Question 10

📗 [1 point] Please enter any comments and suggestions including possible mistakes and bugs with your version of the questions and the auto-grading, and materials relevant to solving the question that you think are not covered well during the lectures. If you have no comments, please enter "None": do not leave it blank.
📗 Answer: .

# Grade


 * * * *

 * * * * *

# Submission



📗 Please do not modify the content in the above text field: use the "Grade" button to update.
📗 Warning: grading may take a few seconds. Please be patient and do not click "Grade" multiple times.


📗 You could submit multiple times (but please do not submit too often): the submission with the highest grade will be counted.
📗 Please also save the text in the above text box to a file using the button or copy and paste it into a file yourself .
📗 You could also load your answers from the text (or txt file) in the text box below using the button . The first two lines should be "##p: 5" and "##id: your id", and the format of the remaining lines should be "##1: your answer to question 1" newline "##2: your answer to question 2", etc. Please make sure that your answers are loaded correctly before submitting them.



📗 Saving and loading may take a few seconds. Please be patient and do not click "Load" multiple times.

# Code

📗 Please submit your code (.m, .txt, or .pdf are all acceptable) on Canvas Assignment P5.
📗 Your coding style and technique will not be graded, but please consider the following:
(1) Add comments to describe what the code is doing.
(2) Indent "for" loops and "if" blocks.
(3) Use descriptive but short variable names.
(4) Add white spaces and/or blank lines for readability.
📗 It is highly recommended that you use the commands and functions from the lectures, but you are allowed to use any built-in MATLAB commands and functions.
📗 Example solution: .m File, .txt File .pdf File.
(1) Please do not use the example solution as the starter code. You should write all the code yourself and only use the example solution as a reference when you get stuck.
(2) Please do not use the example solution as a guide for coding style. It is written so that it only solves a specific version of the problems. You code should be more general: you should define variables for constants, define functions for repetitive actions, and use descriptive variable names.
📗 Please report possible mistakes in the solution, and if you have better (shorter or more efficient) ways of solving the same problem, you can share your code on Piazza (but please do so after the due dates).
📗 If you use one or more lines of code from the example solution, other students in the class, or code you found on the Internet, you must give attribution by putting a comment at the beginning of your code submission, for example:
% Code attribution: P5 example solution.
% Code attribution: (student name)'s P5 solution.
% Code attribution: (student name)'s answer on Piazza: (link to Piazza post).
% Code attribution: (person name)'s answer on Stack Overflow: (link to page).






Last Updated: September 15, 2024 at 1:20 AM