Input Errors and Condition Number - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Input Errors and Condition Number

Description:

How do errors in the input data affect the results of an algorithm ? Let's assume that the algorithm takes a vector ... Add contents of register 1 to register 3 ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 24
Provided by: cass76
Category:

less

Transcript and Presenter's Notes

Title: Input Errors and Condition Number


1
Input Errors and Condition Number
How do errors in the input data affect the
results of an algorithm ??
Lets assume that the algorithm ? takes a vector
of real numbers x (x1, x2, x3, , xn) into
an output y
Lets assume that the ? have continuous 1st
derivatives.
2
Input Errors and Condition Number
Lets define the relative input and output errors
as
Expand ?(x) in a Taylor series and neglect higher
order terms
3
Input Errors and Condition Number
If anyone of the condition numbers has large
absolute values ? ill-conditioned
Otherwise ? well-conditioned
4
Input Errors and Condition Number
Example Consider the following algorithm
Lets assume that the values of a and b have some
error ?a and ?b
The 2 condition numbers are
5
Input Errors and Condition Number
With these two condition numbers the relative
error ?y becomes
Case 1 a gt 0
The condition number remains of the same order as
?a and ?b
?Algorithm is well-conditioned
Case 2 a -b2
The condition number becomes large
?Algorithm is ill-conditioned
6
Programs
The CPU executes instructions coded in
binary Such instructions could look
like 1001100101010011
which could mean Add contents of
register 1 to register 3
A file containing of all this binary instructions
makes an executable program
7
Programs
High-Level languages allow for an easier
notation English-like words and math-like
expressions
Y X 3 WRITE(,) Y
Fortran 90 is a high-level language
The compiler translates into machine
instructions The linker then creates an
executable program The operating system runs the
executable
8
Example of a Problem
Write a program that converts a time given in
hours, minutes, and seconds to one given in
seconds
Algorithm
1. Multiply the hours by 60 2. Add the minutes to
the result 3. Multiply the result by 60 4. Add
the seconds to the result
9
Logical Structure
1. Start the program 2. Reserve memory for
data 3. Write prompt to display 4. Read the time
in hours, minutes, and seconds from keyboard 5.
Convert the time into seconds 6. Write out the
number in seconds 7. End the program
10
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
11
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
lt-- Start of Program
12
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
lt--Comments can appear anywhere in the program
13
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
lt-- Specification Part Declare types and sizes of
data
14
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
lt-- Execution Part All of action statements
15
The Program
PROGRAM convert_time ! Comments start with an
exclamation point IMPLICIT NONE INTEGER hours,
mins, secs, temp WRITE(,) Input the hours,
seconds, and minutes READ(,) hours, mins,
secs temp 60 (hours 60 mins)
secs WRITE(,) Time in seconds , temp END
PROGRAM convert_time
lt-- End of Program
16
Program and File Names
Program and file names are not related PROGRAM
convert_time can be located in file
TimeConversion.f90
Some compilers do not require the
initial PROGRAM name In this case you still
need to end the program with END or END
PROGRAM
17
Specification Part
IMPLICIT NONE INTEGER hours, mins, secs, temp
1. IMPLICIT NONE requires that all variables need
to be declared.
If not, variables are implicitly declared
by Names that start with I-N are INTEGER Names
that start with A-H and O-Z are REAL
You should always use IMPLICIT NONE !!
18
Specification Part
IMPLICIT NONE INTEGER hours, mins, secs, temp
1. IMPLICIT NONE requires that all variables need
to be declared.
2. hours, mins, and secs are used to hold input
data. temp is called a workspace or a
temporary variable In this example the
variables are specified as integer values
19
Execution Part
Write to display WRITE(,) Input the hours,
seconds, and minutes Read the time in hours,
minutes, and seconds from keyboard READ(,)
hours, mins, secs Convert time into seconds temp
60 (hours 60 mins) secs Write results
to the display WRITE(,) Time in seconds ,
temp
20
Assignments and Expressions
temp 60 (hours 60 mins) secs
The RHS is a pseudo-mathematical expression It
calculates the value to be stored
Expressions are much like A-level
formulae (Remember FORTRAN is Formula
Translation) We will cover the detailed rules
later
The LHS temp stores the value in the
variable
21
Sequences and Conditionals
  • Simple algorithms are just sequences
  • A simple algorithm for controlling the
    temperature could be
  • Read the temperature
  • Turn on the heat
  • Whereas it probably should have been
  • Read the temperature
  • If Temperature is below minimum
  • 2.1 Then turn on the heat
  • 2.2 Else turn off the heat

22
Repeated Instructions
The previous program handled only one value
  • A more flexible one would be
  • Start the program
  • Reserve memory for data
  • Repeat this until end of input
  • 3.1 Read the value of hours,
  • 3.2 Convert to seconds
  • 3.3 Write out the result
  • 4. End of Program

23
Data Types
INTEGER for exact whole numbers e.g 1, 21,
-152, 34265,
REAL for approximate fractional numbers e.g 1.2,
21.3, -1.52, 34265.45, ?,
COMPLEX for complex fractional numbers e.g (1.5,
-4.67)
LOGICAL for truth (boolean) values These may
either be .TRUE. or .FALSE.
CHARACTER for strings of characters e,g Type
a number, Result ,
Write a Comment
User Comments (0)
About PowerShow.com