SUNY Geneseo Department of Mathematics

Lab 1—Variables and Expressions

Math 230 02
Spring 2015
Prof. Doug Baldwin

Complete by Monday, February 2
Grade by Thursday, February 5

Purpose

This lesson develops your ability to use variables to store values, and to write calculations as Matlab expressions.

Background

This lesson is based on material in sections 1.3 and 1.4 of Attaway’s book. Information about variables is also covered in the first few minutes of the “Variables and Simple Arrays” video from the University of Edinburgh.

The second problem requires some knowledge of counting and statistics that you can find in the following videos.

Activity

Write Matlab expressions that solve each of the following problems:

Problem 1

Use the quadratic equation to find the x values at which a polynomial of the form ax2 + bx + c is zero. Store a, b, and c in variables. Recall that the quadratic equation says that the polynomial is 0 at the two values x = (-b ± √(b2 - 4ac)) / 2a. You will probably need several Matlab expressions to calculate both x values. Think about whether there are ways to use Matlab variables to connect these expressions in ways that reduce the amount of redundant code in both of them. 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?

Problem 2

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 one 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 would you figure out how many possible sets of 6 numbers between 1 and 59 there are? Write a Matlab expression to do this calculation.

What is the probability that a player who buys 1 ticket will win the jackpot?

How would you figure out how many different choices of numbers will win a second-place prize in a drawing? Write a Matlab expression to calculate this number.

What is the probability that a player who buys 1 ticket will win a second-place prize?

Suppose the jackpot is $50,000,000. How would you figure out the expected profit (i.e., winnings in excess of the ticket price) of a player who buys one ticket? Write a Matlab expression to do this calculation. You may find it helpful to use results calculated by earlier expressions in this one. Feel free to either embed the old expressions in the new one, or to modify the old expressions to store their results in Matlab variables you can use in the new expression.

What does the jackpot have to be in order for a player who buys one ticket to have a positive expected profit? What part(s) of the process of answering this question do you have to do by hand, and what parts can Matlab calculate for you?

(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.)

Follow-Up

I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring a written solution to the exercise to your meeting, as that will speed the process along.

Sign up for a meeting via Google calendar. If you worked in a group on this exercise, the whole group should schedule a single meeting with me. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.