关键词 > EMET3007/8012

EMET3007/8012 - Week 4 Lab

发布时间:2022-09-27

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EMET3007/8012 - Week 4 Lab

Instructions Exercises 1-4 should mostly have been nished last week; but if not, please do work on them.  The main tasks for this week are Exercises 5-9.  If you finish those, feel free to move on to Exercises 10-13.

Exercise 1. Construct the matrices:

a =        .(、)     B =        .(、)

in Matlab. Investigate the colon operator. What do you get if you type A(1:2)? Why? What about A(1:2 :end)? Why?

Exercise 2. Solve the following linear system for x:

        5(7) 

Exercise 3. Using only the diag function, construct the matrix

(0   5   3

Exercise 4.  Compute the product of the elements on the main diagonal of matrix B (from exercise 1).  Compute the determinant of B using det(B).  Do you get the same answers? Why?

Exercise 5.  Write a Matlab program which simulates ipping a loaded coin where the probability of getting a head is 0.7.   That is, a program which says Heads 70% of the time, and Tails 30% of the time.

Exercise 6. Simulate ipping the loaded coin 100 times and record the num- ber of heads.

Exercise 7.  Rey and Kylo are playing a coin-flipping game with a fair coin. When the coin comes up heads, Rey pays Kylo one dollar; if it comes up Tails, Kylo pays Rey one dollar.  Before play, Rey has $10 and Kylo has $5.  The game is over when one of them has no money left. Write a Matlab program to simulate this game.

Exercise 8. Consider the coin-flipping game from Exercise 7. Run this game 100 times, recording the winner each time. How often does Rey win?

Exercise 9. Consider the simulation in Exercise 8. Run this simulation 10000 times (each run of Exercise 8 requires 100 runs of Exercise 7), recording how often Rey wins each in each simulation.   Plot a histogram of Rey’s win proportions. What does this distribution look like?  Use help  histogram to learn about his- tograms.

Exercise 9a.  [This question is tricky. I recommend doing this question last.] Using your results from Exercise 9, find the normal distribution which most closely matches the distribution shown in your histogram. Find a way to display both the histogram and the pdf of the normal distribution on the same graph.

Exercise 10.  Create a function which can be used to evaluate the standard

normal density

φ(α) =  exp 

What is value of φ(2) for the standard normal?

Exercise 11. Create a function which can be used to evaluate the log ≠ density

log j(α | 夕.μ.σ2 ) = log Γ   2(+) 1log Γ  2(夕)  log(πσ 2 )   2(+) 1 log 1 +夕(1) α 一σ μ2 \

[Hint: Use the gammaln function; learn about this function with help  gammaln]

Exercise 12. Using your function from Exercise 11, with  = 5 μ = 一2 σ = 1, use Matlab to nd the value of α which maximises the log ≠ density. Optional: Argue mathematically why the maximiser was 一2.

Exercise 13. Create the matrix

(

H =     0      05      1

(  0(0)         0(0)      0(0)5

using the sparse function.

0

0

0

1

一0.9