18
UNIT 18: COMPUTATIONAL THINKING Errors and rounding

Errors and rounding. How tall are you? What is that in centimetres? So how tall are you in millimetres? Margin of error Sometimes acceptable

Embed Size (px)

Citation preview

Page 1: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

UNIT 18: COMPUTATIONAL THINKING

Errors and rounding

Page 2: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Errors

How tall are you? What is that in centimetres? So how tall are you in millimetres? Margin of error Sometimes acceptable What happens when we start doing operations

though?

Page 3: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Rounding

0 0.5 1.0

Move number to nearest ‘significand’ Easy. What about 0.5?

Round-up Round to even, statistician’s rounding,

banker’s rounding Rounding towards zero (truncating)

Page 4: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Petrol prices

Do these calculations using the prices corrected to the nearest penny. How much do motorists pay for petrol in Hereford? Petrolprices.com take an average of the three prices

given. If we have a 60 litre tank, how much does it cost to fill it?

(Assume it is empty to start). What if we used ‘super’ to fill the same tank? What is the

difference? What if we used diesel to fill the same-size tank? What is

the difference?

Now repeat the calculations but don’t correct the prices.Are your results the same?

Page 5: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Fractional numbers

How do you store a fraction in a computer?

½ easy = 0.5

1/3 more difficult = 0.33333333333333333…33

How many bits are allocated (allowed) for one number? If no limit could use all of a computers memory on one fraction!

Page 6: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Fractional numbers

Most computers use IEEE standard for ‘floating point numbers’

Provides a way to store fractions in the space of an 8- byte number

But, for most numbers it involves an approximation ‘rounding’ “correct” number

to nearest whole number X decimal places X significant figures

‘truncation’ just cut number off at specified limit

Page 7: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Floating point

Whole numbers = (x*1 + x*2+x*4+x*8+x*16etc)

Can store any whole number Fractions =

(x*1/2+x*1/4+x*1/8+x*1/16etc) How would you convey 1/10?

Computers work to 15 decimal places.

Page 8: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Division by zero

Division = sharing Divide these 50 marbles betweenthese 5 buckets

Page 9: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Division by zero Division = sharing Divide these 50

marbles betweenthese buckets:

Page 10: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Division by zero Division by zero crashes

programmes In spreadsheets it returns ‘error’

messages

Page 11: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Overflow and Underflow

Overflow Calculation returns value too large for

storage location Too much memory is being used or required

Underflow Calculation returns a value which is too small

(ie too close to zero) {fractions are tricky} Flush to zero Gradual underflow; subnormal numbers

Page 12: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

User error!

88% of spreadsheets have errors Research: Bad math rampant in

family budgets and Harvard studies http://

www.marketwatch.com/story/88-of-spreadsheets-have-errors-2013-04-17

European Spreadsheet Risks Interest Group 

Peer review Software programs

Page 13: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

User errors

Access this website: Eight of the worst spreadsheet blunders http://www.cio.com/article/131500/Eight_

of_the_Worst_Spreadsheet_Blunders?page=4&taxonomyId=3000

Take one of the stories: find out what happened explain it to the rest of the class what was the loss what was the lesson learnt?

Page 14: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Spreadsheets – quick lesson

Open excel Goto top left (A1) Enter 1 – copy value to 4 rows beneath Go to A1, go right 1 cell (B1) Enter 3 – copy value to 2 rows beneath Goto B4, enter 6, copy value to B5 Goto C1, enter “=A1/$B$1” Copy formula to C2 and C3

Page 15: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Spreadsheets..cont’d

Add the result of C1,C2 and C3 in your head

Note your answer Insert a row below row 3 Goto C4 Enter =sum(C1:C3) – is this the same as

your result? Who is correct?

Page 16: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

More spreadsheets

Copy the formula from C3 to C5 Is the result as expected? Absolute vs relative referencing

Page 17: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

User errors

These happen in the real world with major consequences! Financial loss (corporate level) Job loss (individual level)

Transcription Wrong sign Allowing access to wrong people, wrong version or at

wrong time Using formatting to hide data instead of removing it Adding too many zeros Cut and paste Incorrect data (typo, transcription error) Incorrect formula (typo, cut & paste)

Page 18: Errors and rounding.  How tall are you?  What is that in centimetres?  So how tall are you in millimetres?  Margin of error  Sometimes acceptable

Tasks

1. Convert to binary: 63, 15, 48, 7, 52

2. Convert from binary to decimal: 1101, 11001100, 0011001101, 10101010

3. Convert to hexadecimal from decimal via binary: 15, 18, 33, 61, 46

4. Find the errors in the spreadsheet5. Use the following example to explain

two’s complement:a) 11-63

b) 2-1 (use this to explain why we use it, rather than sign & magnitude) .