SUNY Geneseo Department of Computer Science
CSci 120, Spring 2014
Prof. Doug Baldwin
Complete by Monday, February 3
Or Wednesday, February 5
This lesson asks you to use Matlab variables and expressions to solve a series of mathematical problems.
The basic Matlab concepts you will need are covered in the following places. Read or watch each of these before your recitation on January 31.
In addition, some mathematical material that you will need for the last problem is covered in the following video lectures:
These mini-lectures may be review for some of you, but you should look at them and be sure that you either understand the ideas they describe, or are prepared to ask questions about the videos, before you start the lottery problem below.
Use Matlab expressions and variables to solve each of the following sets of problems.
Note that many of these problems ask you to evaluate the same expression for different values of its variables. The up-arrow key in Matlab’s command window, which allows you to recall, possibly edit, and re-execute previous commands, may be helpful here.
Calculate the length of the hypotenuse of a right triangle, given the lengths of its other two sides. (Hint: recall the Pythagorean theorem, which says that if c is the length of a right triangle’s hypotenuse, and a and b are the lengths of its other two sides, then a2 + b2 = c2.)
Use the quadratic equation to find the x values at which a polynomial of the form ax2 + bx + c is zero. Recall that the quadratic equation says that the polynomial is 0 at the two values x = (-b ± √(b2 - 4ac)) / 2a. Test your Matlab expression(s) on x2 - 2x - 3, which is 0 at x = -1 and x = 3. Now consider the polynomial 3x2 + x + 2. Do you think there are values at which it is 0? What does Matlab say?
Attaway’s textbook describes Matlab’s logical operators && (and), ||
(or), ~
(not), and the exclusive or function xor
(see section 1.6). However, you don’t really need xor
—any logical computation can be done solely in terms of “and,” “or,” and “not” operations. As an example, devise an expression that computes the exclusive or of logical variables p and q, using only those variables and the “and,” “or,” and/or “not” operations. Test your expression in Matlab.
In fact, the previous paragraph is a little too generous: you can actually do any logical computation using only “not” and either “and” or “or” but not both. As an example, devise and test an expression that is equivalent to “p or q,” but uses only those variables and the operators “and” and “not.”
The expression you came up with for “p or q” is almost certainly an instance of a pair of equations called de Morgan’s laws. These equations are usually written as an equality between “not (p and q)” and an expression involving p, q, “not” and “or,” and another equality between “not (p or q)” and an expression involving p, q, “not” and “and.” Transform your expression for “p or q” into one of these forms of de Morgan’s laws.
Consider the following lottery, loosely based on, but considerably simplified from, Powerball: the basic idea of the lottery is that during drawings the lottery managers randomly pick 6 distinct numbers between 1 and 59; players try to guess which 6 numbers will be picked. More formally, a player buys a lottery ticket for $2, which entitles him or her to make a guess about which 6 numbers the lottery managers will draw. If the player guesses all 6 numbers correctly, he or she wins the jackpot for that drawing. If the player guesses 5 but not all 6 of the numbers correctly, he or she wins a fixed second-place prize of $100,000.
How many possible sets of 6 numbers between 1 and 59 are there? What is the probability that a player who buys 1 ticket will win the jackpot?
How many different choices of numbers will win a second-place prize in a drawing? What is the probability that a player who buys 1 ticket will win a second-place prize?
Suppose the jackpot is $50,000,000. What is the expected profit (i.e., winnings in excess of the ticket price) of a player who buys one ticket?
What does the jackpot have to be in order for a player who buys one ticket to have a positive expected profit?
(Before your answers to this problem turn you into an avid Powerball player, note that I believe the lottery in this question actually has better odds of a big payout than Powerball does.)
In your study group’s first face-to-face meeting with me following your “Complete By” date above, I will look over your solutions to the problems, ask you any further questions I have, and answer any questions from you. I may also ask you to demonstrate some of your answers in Matlab. Please bring short written answers to each question to the meeting (diary
output from Matlab showing you solving the problems would be one way to do this). This will speed the meeting along, but because we will also be talking face-to-face, the written answers don’t have to be long or elaborate.
If you aren’t already signed up for a study group meeting during the week following this recitation, please sign up. Make the meeting 15 minutes long, and try to make it at a time all members of your study group can attend. If no such time exists, make it at a time the greatest number of members can attend.