Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
1
Some Fundamental definitions of Error Analysis:
Absolute and Relative Errors:
Absolute Error: Suppose that tx and ax denote the true and approximate values of a
datum then the error incurred on approximating tx by ax is given by
at xxerrore
and the absolute error ae i.e. magnitude of the error is given by
ata xxe
Relative Error: Relative Error or normalized error re in representing a true
datum tx by an approximate value ax is defined by
t
a
t
at
rx
x
x
xx
valuetrue
errorabsolutee
1
and
.100% rr ee
Example:
Given the number is approximated using n = 5 decimal digits (ie. 3.1415).
Determine the relative error due to chopping and express it as a per cent.
05-9293481e9.265358971415.3 errore
05-2150871e2.9492553605)/-9293481e9.26535897(/)1415.3( re
or 150871%294925536200.003-2150871e2.94925536(%) re
Norms for Vectors and Matrices
Norms for vectors:
Let T
nxxxx ),,,( 21 be a vector.
On a vector space V , a norm is a function from V to be the set of nonnegative
real that obeys those three postulates.
0x
if 0x , Vx
2
xx if R , Vx
yxyx if Vyx , (the ‘triangle inequality’)
We can think of x as the length or magnitude of the vector. There are some
important examples:
1l -norm
n
i
ixx1
1
2l -norm
21
1
2
2)(
n
i
ixx
pl -norm 1p
pn
i
p
ipxx 1
1
)(
l -norm
ini
xx
1max
Example1. Find the 1-, 2- and infinity norm for )3,2,1(Tu .
Solution: We have
6321|||| 1 u
14321|||| 222
2 u
3|||| u
Example2. Let nT Ru )1,....,1,1( be the vector of all 1. Find the 1-, 2- and infinity
norm for u .
Solution: We have
n 1...1|||| 1u
n 222
2 1...11||||u
1|||| u
3
Example 3. Let nT n Ru ),....,2,1( , find the 1- and infinity norm foru .
Solution: We have
2
)1(|||| 1
nnu
n||||u
Matrix Norm:
The norm of a square matrix A is a non-negative real number denoted A . There are
several different ways of defining a matrix norm, but they all share the following
properties:
)( 1|I| matrix identity the for
)0 0 ( 0|A| AA iffwith
) ( scalars all forAA
BABA
BAAB
Given a particular vector norm , and matrix A, the norm of A is defined as follows:
}1,:sup{ uRuAuA n
There are some important examples:
}1,,sup{111 uRuAuA n
}1,,sup{222 uRuAuA n
}1,,sup{
uRuAuA n
)(2
AAA T Where )( AAT is the largest eigenvalue of AAT .
n
j
ijni
aA1
1max
n
i
ijnj
aA1
11max
The Frobenius norm of a matrix A , denoted F
A , is a matrix norm similar
4
to the Euclidean norm that is defined to be the square root of the sum of the
absolute squares of the elements of )(: ijaA That is,
)(1 1
2
AAtraA Tm
i
n
j
ijF
( Tr means the trace of A.)
Definition: The trace of a square matrix is the sum of the entries on the main
diagonal.
n
i
iiatr1
)(A
Example 1: Compute the 1,-2-, ∞-, and Frobenious norms of the matrix
12
11A .
Solution: We have that
.3max{2,3}
A
.3max{3,2}1
A
2-norm of 2/1
2 )(|||| AAAA t
e.g.
12
11A Then
23
35
12
11
11
21AAT
Its characteristic equation is:
09)-)(2-(5 023
35det
This gives 0172 2
4572/1
The eigenvalues are: 851.61 and 1459.02
Therefore, .618.2851.6),max( 212 A
Frobenious norm: .6458.271211 2222 F
A
Example 2: Determine 1,-2-, ∞-, and Frobenious norms of the matrix
23
21A .
Solution: We have that
5
.5max{3,5}
A
.4max{4,4}1
A
2-norm of 2/1
2 )(|||| AAAA t
e.g.
23
21A Then
88
810
23
21
22
31AAT
Its characteristic equation is:
064)-)(8-(10 088
810det
This gives 016182 2
260182/1
Therefore, .1306.4),max( 212 A
Frobenious norm: .2426.418)2(32)1( 2222 F
A
Example 3: Determine 1,-2-, ∞-, and Frobenious norms of the matrix
211
121
011
A
Solution: We have that
.4
A
.41A
541
462
123
211
121
011
210
121
111
AAt
The eigenvalues are:
77 ,77 ,0 321
Therefore, 106.377)(2
AAA t
Frobenious norm: .7417.3F
A
Exercise 1:
Determine spectral radius, 1,-2-, ∞-, and Frobenious norms of the following matrix:
6
987
654
321
A
205
132
011
B
121
112
211
C .
Solution:
Exercise 2:
Let A be an mxn matrix:
nmRA
0001
0001
0
0001
0001
Determine 1,-2-, ∞-, and Frobenious norms of the matrix A.
Exercise 3:
Let A be an mxn matrix:
7
nmRA
0000
0000
0
0000
1111
Determine 1,-2-, ∞-, and Frobenious norms of the matrix A.
Matrix Eigenvalue:
Let A be an nxn matrix. An eigenvector is A is a nonzero vector xxA such that
for some scalar . A scalar is called an eigenvalue of A if there is a
nontrivial solution x of xxA . Such an x is called an eigenvector
corresponding to .
If xAx is an eigenvalue equation (and we assume that x is not a zero vector),
then
0I)-det(A 0I)x-(A xAx
This leads to a characteristic polynomial in : )det( IApA
is an eigenvalue of A only if 0Ap .
Spectral radius of an operator A is
||max)()(
AA
= ||max
1i
ni
( )(A is the set of all its eigenvalues of A ).
Example:
Let
52
12A be the matrix and we want to compute its eigenvalues. Its
characteristic equation is:
02)-)(5-(2 052
12det
This gives 01272 0)4)(3(
Therefore, A has two eigenvalues: 3 and 4.
Then the spectral radius of a A is .4)( A
8
Inner Product
Let u, v, and w be vectors in a vector space V, and let c be any scalar. An inner
product on V is a function that associates a real number <u, v> with each pair of
vectors u and v and satisfies the following axioms.
〉,〈〉,〈 uvvu
〉,〈〉,〈〉,〈 wuvuwvu
〉,〈〉,〈 vuvu cc
0〉,〈 vv and 0〉,〈 vv if and only if 0v
Note:
. space for vectorproduct inner general,
, )for product inner Euclidean (productdot
V
nR
vu
vu
Associated Norm
〉,〈||||〉,〈|||| 2 uuuuuu
Let u and v be vectors in an inner product space V.
(1) Cauchy-Schwarz inequality:
vuvu ,
(2) Triangle inequality:
vuvu
The distance between two vectors u, v ∈ V is defined as:
vuvu ),(d
(3) Pythagorean theorem:
u and v are orthogonal if and only if
222 |||||||||||| vuvu
9
Example: Let V = C[a, b] be the vector space of all continuous functions f : [a, b] →
R. For f, g ∈ C[a, b], define inner product:
b
a
dxxgxfgf )()(,
We now define the function versions of the same three norms we have just studied.
For functions f ∈ C[a, b] we define
b
a
dxxf2
2)(f
b
a
dxxf )(f 1
)(f max xfbxa
Exercise 4:
Let xxf )( and .2)( 2 xxxg (f, g ∈ C[-1, 1],)
1. Compute ., gf
Solution: We have
2. Compute norm .f
Solution: We have
3. Compute norm .g
10
Solution: We have
4. Compute d(f, g).
Solution: We have
Exercise 5:
Let xxf )( and .2/)13()( 2 xxg (f, g ∈ C[-1, 1],)
Show that f and g are orthogonal.
Solution: We have to show that < f, g >= 0. We have
So, f ⊥ g.
11
Condition Number
The condition number of a square matrix is the maximum possible error
magnification factor for solving bAx , over all right-hand sides.
Surprisingly, there is a compact formula for the condition number of a square matrix.
.)()( 1 AAAcondA
Example:
9615
654
431
A
2593.08889.16667.3
3704.05556.26667.4
0741.01111.03333.01A
20A
6667.81 A
3340.1736667.8*201 AA .
12
Notes on using MATLAB
Formats for printing numbers.
format short 3.1416
format short e 3.1416e+00
format long 3.14159265358979
format long e 3.141592653589793e+00
Vectors and scalars are special cases. Matrices can be created as follows, A = [1, 1, 1,
1; 1, 2, 3, 4]. This creates a 2×4 matrix A whose first row is (1,1,1,1) and whose
second row is (1,2,3,4).
The dimensions of a matrix A can be found by typing size A.
To create a vector, type x=[1,2,3,4]. The commas are optional, x=[1 2 3 4] gives the
same result.
Thus, x=[0 .2 .4 .6 .8 1] can be created by typing x=0:.2:1.
13
Built-in functions.
pi 3.1415
zeros(3,3) 3×3 matrix of zeros
eye(5) 5×5 identity matrix
ones(10) vector of length 10 with all entries =1
abs(x) absolute value
sqrt(x) square root, e.g. i=sqrt(-1)
real(z), imag(z) real, imaginary parts of a complex
number
conj(z) complex conjugate
atan2(y,x) polar angle of the complex number x + iy
sin(x), cos(x) trig functions
sinh(x), cosh(x) hyperbolic functions
exp(x) exponential function
log(x) natural logarithm
Example of a loop.
for i = 1:4 x(i) = i; end
Example of a conditional.
if a==0; x = a+1; elseif a < 0; x = a-1; else; x = a+1; end
14
Plotting.
plot(x,y) linear plot, uses defaults limits, x and y are vectors
grid draw grid lines on graphics screen
title(’text’) prints a title for the plot
xlabel(’text’) prints a label for the x-axis
ylabel(’text’) prints a label for the y-axis
axis([0, 1, -2, 2]) overides default limits for plotting
hold on superimpose all subsequent plots
hold off turns off a previous hold on
clg clear graphics screen
mesh 3-d plot; type help mesh for details
contour contour plot; type help contour for details
subplot several plots in a window; type help subplot for details
Example: To plot a Gaussian function, type the following lines:
15
Matrix functions.
x = A\b gives the solution of Ax=b
[v,d] = eig(A) eigenvalues in d, eigenvectors in v
inv(A) inverse of a square matrix
rank(A) matrix rank
*, + matrix product and sum
.*, .+ element by element product and sum
’ transpose, e.g. A’
ˆ power, e.g. A ˆ 2
. ˆ element by element power, e.g. A.ˆ 2
m-files. An m-file is a file that contains a sequence of MATLAB commands. Some
m-files are built into MATLAB. A user can create a new m-file using an editor. For
example, an m-file called fourier.m could be created containing the lines:
% % Plot a trigonometric function. %
x = 0:.01:1;
y=sin(2*pi*x);
plot(x,y)
16
In this case, typing fourier would produce a plot of a sine curve. (Note: % in an
m-file denotes a comment line.)
In order to pass arguments to and from an m-file, the word “function” must be on the
first line. For example:
function [x,y] = fourier(n,xmax)
% % Plot a trigonometric function. %
x=0:.01:xmax;
y=sin(n*pi*x);
plot(x,y)
Typing [x,y] = fourier(2,7); plots a sine curve. After execution, the vectors x and y are
available for further calculations.
Useful commands:
type fft lists the contents of the m-file fft.m
save A stores a matrix in a file called A.mat
save saves all variables in a file called matlab.mat
load temp retrieves all the variables from file temp.mat
print prints the current graphics window