SUNY Geneseo Department of Mathematics

Lab 1—Variables and Expressions

Math 230 01
Fall 2015
Prof. Doug Baldwin

Complete by Wednesday, September 16
Grade by Friday, September 18

Purpose

This lesson develops your ability to use variables to store values and to write calculations as Matlab expressions. It also introduces you to scripts as places to write and save Matlab computations.

Background

This lesson is based on material in chapters 2, 3, and 4 of our textbook. Sections 2.1 and 2.2, 3.1 through 3.4, and 4.1 and 4.2 are particularly relevant. We discussed much of what you really need concerning expressions and variables for this exercise in class on September 2. We will further discuss expressions on September 9, and scripts on September 11. 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 scripts that solve each of the following problems. Write a separate script for each problem. I don’t expect these scripts to be much more than series of expressions and comments and assignments to variables, but nonetheless the scripts should help you organize your work and present it to me.

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. Hint: you may find it helpful to use results calculated by earlier expressions in this one.

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.