You are on page 1of 3

SPREAD THE MAT-FINAL ROUND QUESTIONS

1.Given the coefficients of two second order polynomials, find the local extrema (maxima or minima) of the first one. Knowing the X where this point happens, put a marker on both curves at that X value. Plot both curves for three units to the left and right of the inflection point of the first curve

Here is the code to create the coefficients: coef1 = rand(1,3)-0.5; coef2 = rand(1,3)-0.5;

2.Given a square binary matrix, look for any column that are all zeros. Delete that column and the corresponding row. Now with the smaller matrix, repeat this, if you can, deleting both the all zero column and the corresponding row, until there are no all zero columns. Display the final matrix and also display the columns you deleted. For example, if

a=[0 1 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1] Deleting all zero columns and corresponding rows in three steps, 01100 00101 00100 00101 00101

0101 0100 0101 0101

100 101 101

10 11

Your output should be: a=[1 0 1 1] Columns deleted: 1 2 4 The random 5x5 binary matrix a should be generated using the following command: a = full(round(sprand(5,5,0.8))) 3.Figure out if the two given rectangles have a non-zero area of overlap The rectangles are specified as shown below

Just fill in your part of the code until you get the binary variable overlap defined.
ax = sort(rand(1,2)); ay = sort(rand(1,2)); bx = sort(rand(1,2)); by = sort(rand(1,2)); clf rectangle('position',[ax(1) ay(1) diff(ax) diff(ay)], 'edgecolor', 'r') hold on rectangle('position',[bx(1) by(1) diff(bx) diff(by)], 'edgecolor', 'k') axis equal %your code here overlap = %1 for overlap, 0 for non-overlapping

4.Simulations that involve the repeated use of a random-number generator to reproduce a probabilistic event are called Monte Carlo simulations, so called because Monte Carlo has some of the world's most famous gaming casinos. In a roomful of people, at least two of them can be expected to have birthdays on the same day of the year. A common party game is to see if this is true. We wish to find the probability that any two people in a room with n people have birthdays that fall on the same day of the year. Assume that there are 365 days in a year, and assume that the chance of a person being born on each day of the year is the same. A single trial experiment consists of filling an array of size n with integers that are randomly distributed from 1 to 365. If any two elements in the array have the same value, then we say that the trial is "true." Thus, a true trial corresponds to the case when at least two people in the room were born on the same day of the year. Simulate the probability by running, say, 10,000 trials with n people in the room. Do this for n = 2,3, ... , 100. You can use the expressionceil(365*rand(n,1))to compute the day of birth for all the n persons in a single trial. The number of true trials divided by 10,000 is the computed simulated probability. What value of n yields the breakeven point? That is, find the least n for which the probability is 1/2 or more.

You might also like