[SOLVED] math python COMP1730COMP6730 Programming for Scientists

$25

File Name: math_python_COMP1730COMP6730_Programming_for_Scientists.zip
File Size: 518.1 KB

5/5 - (1 vote)

COMP1730COMP6730 Programming for Scientists
Floating point numbers

Announcements
Marks for homework 2 available on Wattle.
Read the news and discussion forums!
Questions about code: use forums or ask tutors! instead of emailing comp1730anu
Feedback survey https: www.surveymonkey.comrBPRK9ZK by course reps Anni, MaxDenzil.

Outline
Numbers in binary and other basesFloating point numbers
Error analysis

Representing Integers

Sequential encoding
A sequential encoding system represents each item words, numbers, etc by a sequence of symbols; the order position of a symbol in the sequence carries meaning, as much as the symbol itself.
For example,
representation interpret as one007700

Positional number system
The position of a digit is the power of the base that it adds to the number.
For example, in base 10:
1864
1 thousand 8 hundreds 6 tens 4 ones1103810261014100
The position of the least significant digit is 0. b01 for any base b.
The representation of any nonnegative integer number is unique, except for leading zeros.

We can count in any base
For example, in base 3: 21200013
236
135 234 033 032 031 130
27292432811
1864
Eachdigitisoneof0,,b1.
nnnnb means a number in base b.

Ancient Babylonians ca 2,000 BC counted in base 60.
31601 46001864
However, they did not have a symbol for 0: can mean 1, 60, 3600, 160, etc.

Binary numbers
Binary numbers are simply numbers in base 2.
1110100100021210
129 128 027 126 025
024 123 022 021 020
1024512256648
1864

Arithmetic
Long multidigit addition, subtraction, multiplication, division and comparison of nonnegative numbers work the same way in any base.
111 01012
01112 11002
100121012 10012 000002 1001002 1011012
02 02 02 02 12 12 12 02 12 12 12 102

Bits and bytes
In the electronic computer, a single binary digit bit is represented by the presence or absence of current in a circuit element.
8 bits make an octet, or byte.
Digital hardware works with fixedwidth number representations words.
Common word sizes: 32bit, 64bit.
Note: Python allows arbitrarily large integers!

Floating point numbers

Representing fractional numbers
Extend the number system to negative positions; decimal point marks position zero.
0.2510
0100 2101 5102
012110 51100
0.012
020 021 122
01012 114
0.2510

Not every fraction has a finite decimal expansion in a given base.
For example,
130.3333 in base 10
150.001100110011 . . . in base 213 0.1inbase3.
Because digital computers work with numbers of fixed width, decimal representation of fractions have finite precision.

Floating point representation
A floating point number in base b, xmbe
consists of three components:the signor ;
the significand m;the exponent e;
The number is normalised iff 1mb.Is 0 a normalised number?

Compact small representation of numbers far from the decimal point.
9
9
1.08101 080000000 .0 7
7
6.4410 0.000000644
1.00000012211110230

1 0000001000000000000000000000002

Floating point types, as implemented in computers, use fixedwidth binary integer representation of the significand and exponent.
In a normalised binary number the first digit is 1, so only the fraction is represented m1.f .
The exponent is biased by a negative constant.
IEEE standard formats:
single: 23bit fraction, 8bit exponent.
double: 52bit fraction, 11bit exponent.
Standard also specifies how to represent 0, ,and nan not a number.

x1s 1.f 2 2e127
10 1.012 2011111002127
1122 264321684127
1.25231.2580.15625
Image from wikipedia.org

Type float can represent infinity:11e320
inf
Most math functions raise an error rather than return inf.
For example, 10, or math.log0.
nan not a number is a special value used to
indicate errors or undefined results.
11e32011e320
nan
math.isinf and math.isnan functions.

Floating point number systems
A floating point number system b, p, L, U is defined by four parameters:
the base b;
the precision: number of digits in the fraction
of the significand p; and
the lower L and upper U limit of the
exponent.
IEEEdoubleprecisionis2,52,1023,1024 with some tweaks.

The numbers that can be represented exactly in a floating point number system are not evenly distributed on the real line.
E.g.,2,2,2,1:
E.g., in a 2, 52, 1023, 1024 system,
the smallest number0 is 2102310308,Actual IEEE double standard can represent
numbers down to410324.
the smallest number1 is 1252
121016.
Rounding the significand to p1 digits causes
a discrepancy, called the rounding error.

Because of rounding, mathematical laws do not always hold for floating point arithmetic.
a11111113.0
b11111111.0
c7.51111111
abcabc
False
abcabc
4.488374116817795e10
Example from PunchEnbodyAlmost never compare floats with .

Error analysis
Let x be the true value and x the approximate measured or representable number.
The absolute error is xxx.The relative error is xxx .
Rounding to p1 digits in base b,
the absolute error is12bpbe, andthe relative error is12bp.
x x

Error propagation
The absolute error fxfx is approximately
proportional to df xxx. dx

IEEE standard specifies that floating point arithmetic operations and some other math functions, e.g., are exact, except for the rounding error in the result.
This does not mean errors do not propagate.Ify x1 x2,theny x1 x2
Also if either x1 or x2 is negative.
Ify xi x2,theny x2 x1 x1 x2 x1x2.

Example, continued:
a1.1111113107, b1.1111111107
and c7.51111111.
ybc1.111111851111111107.
y2531071.1109 assuming double
precision and no error other than rounding.
abcayy plusroundingerror.
When adding floating point numbers, the absolute rounding error is proportional to the magnitude of the largest number that is rounded.
Takehome: Computer numbers ! math. numbers

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] math python COMP1730COMP6730 Programming for Scientists
$25