Escolar Documentos
Profissional Documentos
Cultura Documentos
And
Approximation
1. Structured Programming
Logical Representation
Roots of a quadratic equation
Modeling Of Falling Parachutist
gm
dv c
g v
Exact Solution
v (t )
c
1 e ( c / m )t
dt m
Approximation
Solution
c
v(ti 1 ) v(ti ) g v(ti )ti 1 ti
m
Pseudocode
2. Modular Programming
Numerical methods yield approximate results. We must, therefore, develop criteria to specify
how confident we are in our approximate result.
Although quantities such as , e,, or 7 represent specific quantities, they cannot be expresse
exactly by a limited number of digits. For example, = 3.141592653589793238462643... ad
infinitum. Because computers retain only a finite number of significant figures, such numbers
can never be represented exactly. The omission of the remaining significant figures is called
round-off error.
3.1 Significant Figures
Speedometer
2 Certain digits .. 48 km/h
1 Estimated digit 0.9 km/h
3 Significant digits/figures 48.9 km/h
Odometer
6 certain digits
1 estimated digits
7 Significant digits 87,324.45 km
3.1 Significant Figures
Zeros are not always significant figures because they may be necessary just to locate a
decimal point.
53,800 How many significant figures?
5.38 x 104 3
5.380 x 104 4
5.3800 x 104 5
Zeros are sometimes used to locate the decimal point not significant figures.
0.00001753 4
0.0001753 4
0.001753 4
3.2 Accuracy and Precision
Accuracy.
How close is a computed or measured value to the true value
Precision (or reproducibility)
How close is a computed or measured value to previously computed
or measured values.
Inaccuracy (or bias).
A systematic deviation from the actual value.
Imprecision (or uncertainty).
Magnitude of scatter.
(a)Inaccurate and imprecise;
(b)Accurate and imprecise;
(c)Inaccurate and precise;
(d)Accurate and precise.
4. Numerical Error
True error
true error
True fractional relative error
true value
true error
True percent relative error, t 100%
true value
True value will be known only when we deal with functions that can be solved analytically
(simple systems). In real world applications, we usually not know the answer a priori. An
alternative is to normalize the error using the best available estimate of the true value
Then
Approximate error
a 100%
Approximation
Iterative approach, example Newtons method
The sign : (+ / -)
When performing computations, we may not be concerned with the sign of the error, but we
are interested in whether the percent absolute value is lower than a prespecified percent
tolerance
Computations are repeated until stopping criterion is satisfied.
a s Pre-specified
specified % tolerance based
on the knowledge of your
solution
s (0.5 10(2-n) )%
we can be assured that the result is correct to at least n significant figures.
xample
a s
Computer Algorithm for Iterative
Calculations function [fx,ea,iter] = IterMeth(x,es,maxit)
% Maclaurin series of exponential function
% [fx,ea,iter] = IterMeth(x,es,maxit)
Pseudocode % input:
% x = value at which series evaluated
% es = stopping criterion (default = 0.0001)
% maxit = maximum iterations (default = 50)
% output:
% fx = estimated value
% ea = approximate relative error (%)
% iter = number of iterations
% defaults:
if nargin<2|isempty(es),es=0.0001;end
MATLAB if nargin<3|isempty(maxit),maxit=50;end
% initialization
iter = 1; sol = 1; ea = 100;
% iterative calculation
while (1)
solold = sol;
sol = sol + x ^ iter / factorial(iter);
iter = iter + 1;
if sol~=0
ea=abs((sol - solold)/sol)*100;
end
if ea<=es | iter>=maxit,break,end
end
fx = sol;
end
5. Round-off
off Errors
Roundoff errors arise because digital computers cannot represent
some quantities exactly.
Numbers such as p, e, or 7 cannot be expressed by a fixed
number of significant figures.
Computers use a base-2 2 representation, they cannot precisely
represent certain exact base-10
10 numbers.
Fractional quantities are typically represented in computer using
floating point form, e.g.,
Integer part
exponent
m.be
mantissa Base of the number system
used
Integer Representation.
(a) decimal (base 10) and the (b) binary (base 2) systems work
The representation of the decimal integer -173 on a 16-bit
bit computer using the signed magnitude method.
Thus, a 16-bit
bit computer word can store decimal integers ranging from -32,768 to 32,767
32-bit integers would range from 2,147,483,648 to +2,147,483,647
Floating-Point
Point Representation
Integer part
exponent
m.be
mantissa Base of the number system
used
1
0.029411765 Suppose only 4
34 decimal places to be stored
0 1
0.029410 m 1
2
Normalized to remove the leading zeroes. Multiply the mantissa by
10 and lower the exponent by 1
0.2941 x 10-1
Truncation errors are those that result from using an approximation in place of an exact
mathematical procedure.
Taylor Series
where
Approximation of a Function with a Taylor Series Expansion