Академический Документы
Профессиональный Документы
Культура Документы
Lecture 1 : Introduction
subhabrata das assam engineering college
Evaluation Plan
Course Contents
Syllabus Contents : Introduction to scientific computing. Representing numbers in a computer: scalar data types; Variables and constants: guidelines for variable names. Assignment statements: mathematical and logical operators; Keyboard input and screen output; Writing a simple, linear program. Conditional statements; arrays and subscripts; loops. File ; plotting; Functions and subroutines. Program design; writing well structured programs; debugging techniques. Scientific applications of computer programs; Introduction to Matlab Solving nonlinear equations; Numerical integration; Data analysis, plotting and smoothing; Simulating simple physical, chemical and/or mathematical systems. Simulation: the simple programming approach to difference equations. Differential Equations
Scientific Computing
Techniques & Tools for modeling, solving, analysis and visualization
Workflow of SC
An Example
Problem Identification:
An Example
Modeling:
Model is an abstract representation of a real world process or phenomenon.
An Example
Modeling:
Model is represented by a mathematical formalism
An Example
Putting it together:
Another Example
Another Example
Another Example
Main Memory:
Stores the program being executed and the data used by the program. Faster but volatile and smaller size in nature.
Secondary Storage:
Capable of storing considerably more information than the main memory permanently. However they are slower compare to the main memory.
I/O devices:
Connected to the bus either directly or through an I/O controller. Data moves through the bus between I/O devices and the main or the secondary memory.
Bus :
Central communication facility of a computer. Data and instructions are move through the bus among the above devices attached to it.
Fetch-decode-execute cycle:
Control units manner of executing instructions: Step 1: Next instruction is fetched from the main memory into the IR. Step 2: The type of operation for the instruction is decoded. Step 3: The data used by the instruction is located and brought into the appropriate registers, and Step 4: The instruction is then executed.
Memory Address:
Each byte in the memory has an address, starting from 0,1,2,. And ending at N-1, if N is the number of bytes in the main memory.
Bit:
Byte are usually 8 bits. Bit means either 0 or 1.
Words:
Collection of one or more consecutive bytes.
Power of 2:
The size of memory is chosen to be power of 2 in computer. Reason being that numbers inside the computer are represented in binary, and if we allocate a fixed number of bits to represent numbers those bits can represent is always a power of 2. Specifically, if we use k bits, we can represent numbers from 0 to 2k-1, a range of 2k different numbers.
Number Representations
We are used to base/radix 10 (decimal)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 10, 20, 30, , 100 10, , 100, , 1000, , 10 000
17
Decimal
Decimal Example: 1041.20310 :
18
Number Representations
General radix r number, Nr
dp dp-1 d2 d1 d0 . rp rp-1
Represents:
d1 d2 dq r-1 r-2
r2 r1 r0
r-q
19
Binary
Binary Example: 1001.1012 :
23
Represents:
22
21
20
2-1
2-2
2-3
20
Example:
(lsb)
(msb)
21
(msb)
(lsb)
24
= 158 = D16
(lsd) (msd)
26
27
28
NOTE: for fractional conversion, move from left to right and pad at right end:
0.110011010112
0.112 = 0.(110)2
Unsigned Integer
Follows a natural binary coding. Range of integers that can be represented is from 0 to 2n-1
30
Unigned integers
Follows a natural binary coding. Range of integers that can be represented is from 0 to 2n-1
0 0 0 0 1 1 1 0 1 0 0 0 1 1 1 0
27
= +14
= +142
26
25
24
23
22
21
20
31
Magnitude
0 0 0 0 1 1 1 0
sign bit
32
= +14
1 0 0 0 1 1 1 0
26 25 24 23 22 21 20
= 14
27 26 25 2 4 23 22 21 20
(128) (64) (32) (16) (8) (4) (2) (1)
1
128
= 128
35
64 + 32 + 16 + 8 + 4 + 2 + 1
= +127
36
Positive values <= 127 use same 8-bit pattern as unsigned equivalent Negative values use bit patterns from upper half of unsigned integer range
positive range is reduced to allow both positive and negative values to be represented in a single format
37
011111112 011111102 011111012 ... 000000102 000000012 000000002 111111112 111111102 ... 100000102 100000012 100000002
+12710 +12610 +12510 ... +210 +110 010 -110 -210 ... -12610 -12710 -12810
signed and unsigned values differ by 256 (28) for negative numbers
12710 12610 12510 ... 210 110 010 25510 25410 ... 13010 12910 12810
38
39
negative numbers
must have MSB =1 (worth 1 * 2n-1) min value =10000, max = 11111 = -110
40
2 2 2 2 2 2
= = = = = =
35 17 8 4 2 1 0
1 1 0 0 0 1
answer: 00100011
read up, padding with 0s to 8 bits stop confirm answer is positive: MSB = 0
41
42
2 2 2 2 2 2 2 2
= = = = = = = =
1 0 1 1 1 0 1 1
answer: 11011101
read up confirm answer is negative: MSB = 1
11011100
+1
11011101
add 1
answer: 11011101
43
(128) (64)
0
44
0
+
1 = +103
64 + 32
4 + 2 + 1
27 26 2 5 24 23 22 21 2 0
(32) (16) (8) (4) (2) (1)
1
45
0
+
1
4
0 = 60
128+ 64
11000100 00111011 +1
add 1
00111100
finally, negate the decimal value
Answer: 6010
46
Signed addition
Twos complement whats so great?
the addition process is the same for any mix of positive and negative numbers
+ve plus +ve +ve plus ve -ve plus +ve -ve plus -ve
48
Scientific notation
Same idea works in binary
sign: + or
1.01101 21101
Scientific notation
Advantages
very wide range of representable numbers
limited by range of exponent
Disadvantages
some values still not exactly representable
e.g.,
50
Floating point
Binary representation of numbers using a scientific notation style
IEEE754 standard sign mantissa
Floating point
Sign (S)
one bit 0 number is positive 1 number is negative
0 01111111
10000000000000000000000 10000000000000000000000
+1.5
sign bit
52
1 01111111
1.5
Floating point
Exponent (E)
could be represented using twos complement signed notation However, represented using excess-k notation represented value in exponent field is k more than the intended value k is constant (for C float, k = 127)
exponent field 00000001 (110) exponent field 01111111 (12710) exponent field 11111110 (25410) exponent is 126 exponent is 0 exponent is +127
exponent fields of 000...000 and 111...111 reserved for special meanings all bits 0: denormalized numbers and zero all bits 1: infinity and not-a-number (indeterminate)
53
Floating point
Mantissa (M) is normalized
exponent is chosen such that 110 mantissa < 210
23 22 21 20 21
Floating point
Mantissa(M)
represented as fixed-point value between 1.000...2 and 1.111...2 first bit (before the point) is always 1
dont waste a bit to store with the number just assume it always exists
fixed precision
for C float, 23 bits available
plus 1 implicit bit 24 significant bits
mantissa sometimes called significand The value represented by S,E, & M is (-1)S(2E127)(1.M)
55
Floating point
Example: 1152010 as a C float
= 1.4062510 213
sign = 1 because number is negative
mantissa = 1.4062510 = 1.011012, so store 01101 (skip leading 1), pad on right with 0s
1 10001100 01101000000000000000000
exponent = +1310, so store 13 + 127 (excess) = 14010 = 100011002
56
Exercise
What is represented by
1 10000111 10100000000000000000000
What is represented if the exponent bits are 01111000 instead? What is represented it the exponent bits are 00000000 ? ( note that there is no 1 at the front of the mantissa when the exponent is all zeros)
Exercise
What is the value of?
0 11111111 11111111111111111111111 And 0 00000000 00000000000000000000000
Answer :
(-1)0 * 2255-127*(1.11..1) = 2128*(2-2-23) approximately 2129 or about 6.81*1038 2-127 * 2-23 = 2-150 approximately or about 7*10-46
Floating point
C has floating point types of various sizes 32 bits (float)
1 bit sign, 8 bits exponent, 23 (24) bits mantissa, excess 127
64 bits (double)
1 bit sign, 11 bits exponent, 52 (53) bits mantissa, excess 1023
59
Floating point
C does many calculations internally using doubles
most modern computers can operate on doubles as fast as on floats may be less efficient to use float variables, even though smaller in size long double operations may be very slow may have to be implemented by software
60
11111111 reserved for infinity (and not-a-number, NaN) positive: 1.1111...2 2127 = 3.403...10 1038 negative: 1.1111...2 2127 = 3.403...10 1038
solution: use a floating point format with a larger exponent double (11 bits), long double (15 bits)
61
00000000 reserved for zero ( and denormalized numbers where implied bit is 0 and exponent = -126 ) positive: 1.000...2 2126 = 1.175...10 1038 negative: 1.000...2 2126 = 1.175...10 1038
underflow occurs if a calculation produces a number smaller than the representable limit
rounds down to zero
solution: use a floating point format with a larger exponent double (11 bits), long double (15 bits)
62
63
65
two floating point numbers are equal iff they have the same bit pattern otherwise one is less than the other
compare sign bits if different, order is then known if same, compare exponent fields if different, order is then known if same, compare mantissas order is then known
66