error: finding creative ways to screw up cs 170: computing for the sciences and mathematics

33
Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Upload: jade-obrien

Post on 28-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Error: Finding Creative ways to Screw Up

CS 170:Computing for the Sciences

and Mathematics

Page 2: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Administrivia

Last time Basics of modeling Assigned HW 1

Today HW1 due! Assign HW 2

Monday 9/13– NO CLASS

Page 3: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Error

What is the value of a model… That is completely wrong

That is a perfect match to a physical system

That may be off by as much as 5%

Page 4: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Types of Error

Input Data Errors Faulty/inaccurate sensors, poorly calibrated, mis-read

results..

Modeling Errors Poor assumptions, bad math, mis-understanding of

system

Implementation Errors Bug in computer program, poor programming Precision

The limits of finite number representation

Page 5: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Input Data Errors

NSIDC Sensor drift led to their real-time sea ice estimates to

be off by over 500,000 km2

Still only off by 4% http://nsidc.org/arcticseaicenews/2009/022609.html

Page 6: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Modeling Errors

Obvious type: math formulation errors, mis-writing a formula, etc.

By virtue of making assumptions and simplifications, models will have “error” versus reality. This isn’t necessarily a bad thing, as long as we manage it

well

Lord Kelvin used his knowledge of temperature dissipation to estimate that the earth was between 20-40 million years old. Actual: ~12 billion Assumed there was no heat source but the sun

Page 7: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Implementation Errors

Incorrect programming (a “bug”) Didn’t implement the model correctly

Wrong equations Mis-defined inputs/outputs Implemented the solution to a different problem

Precision Errors Computers only have so much space to store numbers This limits the range and precision of values!

Page 8: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Precision Errors

In a computer, a number is stored in a number of bits (binary digits) IEEE 754 standard floating point

Variation on standard normalized scientific notation single-precision is 32 bits double-precision is 64 bits

Stored in 3 parts sign (1 bit) – is it positive or negative? magnitude – what is the exponent? mantissa/significand – what is the number?

i.e. 6.0221415 × 1023

Page 9: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Exponential notation

Example: 698.043990 103

Fractional part or significand? 698043990

Exponent? 3

Normalized? 6.98043990 105

Page 10: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Significant digits

Significant digits of floating point number All digits except leading zeros Number of significant digits in 698.043990

103? 9 significant digits

Precision Number of significant digits

Page 11: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Round-off error

Problem of not having enough bits to store entire floating point number

Example: 0.698043990 105 if only can store 6 significant digits, rounded? 0.698044 105

Do not test directly for equality of floating point variables Note that many numbers that seem “safe” really aren’t!

i.e. 0.2 is an infinite repeating series when expressed in binary

Page 12: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Absolute error

|correct – result|

Example: correct = 0.698043990 105 and

result = 0.698043 105

Absolute error = ? |0.698043990 105 - 0.698043 105| = 0.00000990

105 = 0.990

Page 13: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Relative error

|(correct - result) / correct|

Example: (correct - result) = 0.990 and

correct = 0.698043990 105

0.990/(0.698043990 105) = 1.4182487 10-5

Page 14: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Relative error

Why consider relative errors? 1,000,000 vs. 1,000,001

1 vs. 2

Absolute error for these is the same!

If exact answer is 0 or close to 0, use absolute

error Why?

Page 15: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Addition and subtraction errors

Beware if there is a big difference in the magnitude of numbers!

Example: (0.65 105) + (0.98 10-5) = ? 65000 + 0.0000098 = 65000.0000098

Suppose we can only store 6 significant digits? 65000.0 = (0.650000 105)

Page 16: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Associative property

Does not necessarily hold!

Sum of many small numbers + large number may not equal adding each small number to large number

Similarly, distributive property does not necessarily hold

Page 17: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

To reduce numerical errors

Round-off errors Use maximum number of significant digits

If big difference in magnitude of numbers Add from smallest to largest numbers

Page 18: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Error Propagation (Accumulated Error)

Example: repeatedly executing:t = t + dt

Better to repeatedly increment i and calculate:

t = i * dt

Page 19: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Overflow/underflow

Overflow - error condition that occurs when not enough bits to express value in computer

Underflow - error condition that occurs when result of computation is too small for computer to represent

Page 20: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Truncation error

Truncation error Error that occurs when truncated, or finite, sum is

used as approximation for sum of infinite series

ex 1 xx2

12x3

123

x4

1234

xn

n!

e 111

12

1

123

1

1234

1

20!

1

21!

1

22!

1

23! 2.0510 20

Page 21: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Error is Not Inherently Bad

Almost all of these issues can be managed and controlled!

A certain amount of error is normal

What’s important is that we: Know how much error there might be Keep it within a bound that allows the results to still

be valid

Page 22: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics
Page 23: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Rates: The Basics of Calculus

Page 24: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Calculus

Mathematics of change

Two parts Differential calculus Integral calculus

Page 25: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Rates

“Rate of Change” Often depends on current amounts

Rates are important in a lot of simulations growth/decay of…

populations materials/concentrations radioactivity money

motion force pressure

Page 26: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Height (y) in m vs time (t) in sec of ball thrown up from bridge

average velocitychange in position

change in times(b) s(a)

b a

Page 27: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Average velocity

between 0 sec & 1 sec?between 1 sec & 2 sec?between 0.75 sec & 1.25

sec?Estimate of

instantaneous velocity at t = 1 sec?

Time (t) in seconds

Height (y) in meters

0.00 11.0000

0.25 14.4438

0.50 17.2750

0.75 19.4938

1.00 21.1000

1.25 22.0938

1.50 22.4750

1.75 22.2438

2.00 21.4000

2.25 19.9437

2.50 17.8750

2.75 15.1937

3.00 11.9000

3.25 7.9938

3.50 3.4750

3.75 -1.6563

Page 28: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Derivative

Derivative of y = s(t) with respect to t at t = a is the instantaneous rate of change of s with respect to t at a (provided limit exists):

instantaneous velocity at 1 sec limt 0

s(1t) s(1)

t

s'(a) dy

dt ta

limt 0

s(at) s(a)

t

Page 29: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Derivative at a point is the slope of the curve at that point

Page 30: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Differential Equation

Equation that contains a derivativeVelocity function

v(t) = dy/dt = s'(t) = -9.8t + 15

Initial condition y0 = s(0) = 11

Solution: function y = s(t) that satisfies equation and initial

condition(s) in this case:

s(t) = -4.9t2 + 15t + 11

Page 31: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Second Derivative

Acceleration - rate of change of velocity with respect to time

Second derivative of function y = s(t) is the derivative of the derivative of y with respect to independent variable t

Notation s''(t) d2y/dt2

Page 32: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

Systems Dynamics

Software package that makes working with rates much easier.

Components include: “Stocks” – collections of things (noun) “Flow” – activity that changes a stock (verb) “Variables” – constants or equations – converter “Connector” – denotes input/information being trasmitted

Page 33: Error: Finding Creative ways to Screw Up CS 170: Computing for the Sciences and Mathematics

HOMEWORK!

READ pages 17-48 in the textbook

On your own Work through the Vensim PLE tutorial Turn-in the final result files on W:

Vensim is being deployed tonight. If there is a problem, I will notify everyone ASAP.

NO CLASS on Monday