Beruflich Dokumente
Kultur Dokumente
SCIENTIFIC COMPUTING
teacher
Davide Fransos
davide.fransos@polito.it
Lecture n° 1
Preliminaries
Scientific computing deals with methods we use to obtain a numerical
solution for mathematical problems whose analytical solutions is far too
complex.
Ex: solve a 1000 linear equation system with 1000 unknowns using pen and
paper and a method you remember from high school. Ok?
Scientific computing
Preliminaries
An example:
Computational
simulation
Mathematical model
Model solution
(through scientific computing)
Why is SC important?
Preliminaries
Computational simulation, and though scientific computing, has application in every
field of engineering.
Why is SC important?
Preliminaries
Course The course will explore four classical areas of scientific
content computing:
Linear systems
Eigenvalues
and an exercise part devoted to scientific programming:
The topics will be covered in a similar way and with a similar language as in:
A. Quarteroni, F: Saleri, P. Gervasio, Scientific Computing with MATLAB and
Octave, Springer
Please note that course slides are just a support to the oral presentation of the
Preliminaries topics during lectures, not a textbook.
Machine numbers and operations
We want our computer execute algebraic operations
(in the applications we mentioned before they are many, we
often talk about billions of algebraic operations to be
executed in few days or hours)
Course content
Preliminaries
Approximation of functions and data
A man who really wanted to drink his coffee at a
precise temperature measured that a coffee who gets
out from the coffee machine at 50° and is put into a
ceramic cup at room temperature (16°) colds down
following the scheme:
Course content
Preliminaries
Approximation of functions and data
60
dati misurati
55
50 ? a vs b ?
Temperatura [°C] 45
40 39
35
30
a
25
b
20
0 500 1000 1500 2000 2500 3000 3500
tempo [s]
Course content
Preliminaries
Approximation of functions and data
A closer look
40
39
a
b
reality
38.5
38
1200 1250 1300 1350
tempo [s]
Course content
Preliminaries
Linear systems
Alcoholic fermentation:
Course content
Preliminaries
Linear systems
a(C6H12O6) + b(O2) + c(NH3) → C6H10NO3 + d(H2O) + e(CO2) + f(C2H6O)
6a = 6 + e + 2f
6a + 2b = 3 + d + 2e + f ⎧ −e − 2 f = 6 − 6 (144 /180Y )
c=1 ⎪
⎪ 2b − d − 2e − f = 3 − 6 (144 /180Y )
12a + 3c = 10 + 2d + 6f ⎨
Rb - e = 0 ⎪ −2d − 6 f = 7 − 12 (144 /180Y )
⎪
a = 144/180Y ⎩ Rb − e = 0
what if in place
? of 4x4 we had
10000x10000 ?
⎡ 0 0 −1 −2 ⎤⎡ b ⎤ ⎡ 6 − 6 (144 /180Y ) ⎤
⎢ ⎥⎢ ⎥ ⎢ ⎥
and then ⎢ 2 −1 −2 −1 ⎥⎢
d ⎥ = ⎢ 3 − 6 (144 /180Y ) ⎥
⎥ ⎢ 7 − 12 (144 /180Y ) ⎥
⎢
⎢⎣
0 −2 0 −6
R 0 −1 0
⎥⎢
⎥⎦ ⎢
⎣
e
f ⎥ ⎢
⎦ ⎢⎣ 0
⎥
⎥
? how to solve it?
⎦
A x b
Ax = b
(matrix) (vector) (vector)
Course content
Preliminaries
First steps in Matlab
⎡ 0 0 −1 −2 ⎤⎡ b ⎤ ⎡ 6 − 6 (144 /180Y ) ⎤
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎢ 2 −1 −2 −1 ⎥⎢
d ⎥ = ⎢ 3 − 6 (144 /180Y ) ⎥
⎢ 0 −2 0 −6 ⎥⎢ e ⎥ ⎢ 7 − 12 (144 /180Y ) ⎥
⎢⎣ R 0 −1 0 ⎥⎦ ⎢ f ⎥ ⎢ ⎥
⎣ ⎦ ⎢⎣ 0 ⎥
⎦
A x b
% memorise a number in Matlab
% measured by the sensor
intuitive % measured by the sensor
no need to % memorise a vector in Matlab
declare
variables
% memorise a matrix in Matlab
Course content
Preliminaries
Machine A common problem: thinking that operations executed by a
computer are always correct.
numbers and
operations See http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html
and look at some examples of how this can be false!
Machine numbers
Less spectacular but…
n xn n xn
01 1.00000000 15 3.14159263
02 2.00000000 …
03 2.82842712 25 3.14245127
04 3.06146746 …
05 3.12144515 29 3.46410162
06 3.13654849 30 4.00000000
What happened ?
Machine numbers
and operations Machine numbers
Number systems
Storing
numbers on a We are used to represent numbers with the 0 .. 9 digits,
but this can be sometimes non optimal.
computer
!!!
Decimal system:
Binary system:
1111 = 1⋅ 2 + 1⋅ 2 + 1⋅ 2 + 1⋅ 2
3 2 1 0
notation: (15 )10 = (1111)2
Storing numbers on
a computer Machine numbers
Representing Finite memory!
numbers on a
computer
We have to choose a maximum number
of digits we can use to represent
numbers
Example: INTEGERS
base N = 2, 32 bit
In the standard representation you want to include in fact also the negative integers.
You can then translate the available integers in order to centre them on the zero:
Representing numbers on
a computer Machine numbers
From Matlab documentation
Representing numbers on
a computer Machine numbers
Example: REAL numbers - floating point representation
integer
(exponent)
a = pN q
real number
(mantissa)
−1
normalised
N ≤ p ≤1 floating-point
representation
that is equivalent to
p = 0. a−1 …
always zero! different from zero!
Representing numbers on
a computer Machine numbers
Exercise
Representing numbers on
a computer Machine numbers
Storing a = pN q in a computer means:
sign of a
normalised exponent normalised mantissa
0 ≤ q* ≤ 255 p = 0.1a−2 …a−23a−24
q* = 0 ⇒ a = 0
q* = 255 ⇒ a = ∞, −1,… as N=2 it will always be
1, then I can avoid its
−126 ≤ q ≤ 127, q = q * −127 storage
(false if N>2!)
a = ( −1) ⋅ p ⋅ 2
s q*−127
We'll have
Representing numbers on
a computer Machine numbers
a = ( −1) ⋅ p ⋅ 2
s q*−127
32 bit !
Representing numbers on
a computer Machine numbers
Examples (base N=10, let’s keep it simple)
N=10 base
t=5 digits for the mantissa
m=-126 minimum exponent
M=127 maximum exponent
Representing numbers on
a computer Machine numbers
When two numbers are machine numbers and the results of an operation involving
them is again a machine number, is everything ok?
M1 + M 2
M= where M2 is the largest possible machine number and M1 is smaller
2
M is then a machine number but:
⎪ x2 ⎜ ⎟ + 1, if x2 > x1
⎪⎩ ⎝ x2 ⎠
Representing numbers on
a computer Machine numbers