Download Matlab Homework: Mathematics of Engineering ME17, Spring 2008 - Prof. J. M. Moehlis and more Assignments Mechanical Engineering in PDF only on Docsity! Mathematics of Engineering - ME17 Spring 2008 Homework #3 - Due Friday, April 25, in class 1. (10 points total) (a) (2 pts) Write down a Matlab command to assign the matrix 3 2−6 1 5 −4 to a variable named M. (b) (2 pts) According to Matlab, what are M(1,2), M(:,2) and M(3,:) equal to? (c) (2 pts) According to Matlab, what is M.^2 equal to? (d) (2 pts) According to Matlab, what is M’*M equal to? (e) (2 pts) Explain why Matlab gives an error if you try to evaluate M’.*M 2. (15 points total) (a) (10 pts) Suppose that you throw a projectile in a constant gravitational field. Let’s say that the initial position is (x0, y0) = (0, 10 m), the initial velocity is (v0x, v0y) = (5 m/s, 10 m/s), and the gravitational acceleration is (ax, ay) = (0,−10 m/s2). From basic physics, we know that x(t) = v0xt + x0, y(t) = 1 2 ayt 2 + v0yt + y0. Write a Matlab program in which you take t = 0:0.1:3 and use the above formulas to find matrices (more precisely, row vectors) with the same size as the t matrix and with the corresponding instantaneous values of x and y. Then plot x vs. t, y vs. t, and y vs. x for the time interval 0 ≤ t ≤ 3; use the subplot command to make these all come out on one figure. Also, make sure to label all axes, including units! Please turn in a printout of your program, and a printout of the requested Matlab figure. (b) (5 pts) Determine the approximate values of t and x at which y = 0. This can be accomplished by finding the element of your y matrix which is closest to zero, then viewing 1 the corresponding elements of your t and x matrices. For example, if y(12) is the closest matrix element to zero, report the values of t(12) and x(12). 3. (10 pts) Plot the data x = [1 6 11 16 21 26 31 36 41 46] y = [10 360 1210 2560 4410 6760 9610 12960 16810 21160] using the Matlab commands plot(x,y) semilogx(x,y) semilogy(x,y) loglog(x,y) One of these should give a straight line. Using the y-intercept and slope of this line, determine the functional relationship y(x). Please turn in a printout of the Matlab plot which shows the straight line, and whatever calculations you used to determine y(x). 4. (20 pts total) Consider the following variation of the final round of the classic TV game show Let’s Make A Deal. There are three doors, and behind one of them there is a car, while behind the other two are goats. You are asked to choose one of the doors, and, without loss of generality, you choose Door 1. Now, the host Monty Hall opens either Door 2 or Door 3, behind which is a goat. (He never opens up the door with the car behind it.) Monty now gives you the choice: do you want to stick with Door 1, or switch to the other door. What should you do? Or does it matter? (a) (15 pts) No doubt you would prefer to win a car than a goat. Write a Matlab program to determine, from a probabilistic standpoint, whether it’s better to stick with Door 1 or to switch to the other door which Monty didn’t open. The idea here is to simulate, say, 1000 different random realizations of the game. For each realization, there is a probability of 1/3 that the car is behind Door 1, a probability of 1/3 that the car is behind Door 2, and a probability of 1/3 that the car is behind Door 3. Use the “rand” command to determine which door it is behind for each realization. Next, for each realization determine, for each strategy (stay with Door 1 or switch), whether or not you win the car. Keep track of how many times you win for each strategy. The estimate for the probability that you win the car for a given strategy is equal to the number of times you won divided by the total number of tries. Doing simulations like this to estimate probabilities is known as the Monte Carlo method. Please turn in a copy of your Matlab program, and the probabilities of winning for the two strategies as determined from your program. (b) (5 pts) We can also solve this problem exactly. There are three equally probable arrangements: the car could be behind Door 1, Door 2, or Door 3, with the other doors 2