vuoi
o PayPal
tutte le volte che vuoi
Accuracy of the LU Factorization
1 Accuracy of the LU Factorization8. 1 0 0 01 0 0 0 1/3 1 0 01/3 1 0 0 L =L = 21 1/2 1 1 01/2 1 1 0 −3/5−3/5 1/4 9/10 11/4 9/10 1 1 1/2 1/3 1/41 1/2 1/3 1/4 0 1/12 4/45 1/120 1/12 4/45 1/12 U =U = 21 −1/180 −1/120−1/180 −1/120 0 00 0 0 0 0 1/28000 0 0 1/2800 1 0 0 01 0 0 0 0 0 1 00 0 1 0 P =P = 21 0 1 0 00 1 0 0 0 0 0 10 0 0 111. %computing the norm (to inf) of the differences between the matrices1 X = L 1-L 2;2 Y = U 1-U 2;3 Z = P 1-P 2;4 normX = norm(X,inf);5 normY = norm(Y,inf);6 normZ = norm(Z,inf);712. −16||X|| ·= 2.220446049250313 10∞ −18||Y || ·= 1.734723475976807 10∞||Z|| = 0∞13. Comparing the value of the norms with the value of machine epsilon we can see that||X|| ||Y ||is equal to ε and is lower. From the mathematical
point of view, since ∞ MA satisfies the hypothesis, we expect the solution to be unique and therefore, the threenorms to be null. From a computational point of view, even if the norms are differentfrom zero, the two values are below the machine precision. Therefore, we can considerthe results null and the theorem for existence and uniqueness of the LU factorization withpivoting numerically satisfied. This statement is also proved by comparing the values ofthe three matrices in rational format, which are exactly the same for each pair.
22 Cost of LU factorization
4.7. * 0*c = 7.442278142268356 100* -2* = 3.782389536262116 10c19.
33 Comparison between direct and iterative methods
2. As we can see from the graph as n increases, the difference in time taken by thetwo functions also drastically increases. For a large number of operations the numericalimplementation becomes crucial to obtain results in the shortest possible time.
5. %LU factorization
with pivoting1 n = zeros(40,1); %initializing variables
2 tel LU user = zeros(40,1);
3 for i=3:42
4 n(i-2) = (i-2)ˆ2; %vector which collects size of every matrix
5 G = delsq(numgrid('S',i));
6 k = 0.01;
7 A = G+k*eye(n(i-2)); %matrix i
8 x = ones(n(i-2),1); %definition of vector x
9 b = A*x; %definition of vector b
10 tic
11 [L,U,P] = lu factorization with pivoting(A); %factorization
12 y = L\(P*b); %resolution of the 1st linear system
13 x = U\y; %resolution of the 2nd linear system
14 tel LU user(i-2) = toc;
15 end
16 47. %Jacobi method
1 tel J = zeros(40,1); %initializing variables
2 niterJ = zeros(40,1); % n has already been computed
3 for i=3:42
4 G = delsq(numgrid('S',i));
5 k = 0.01;
6 A = G+k*eye(n(i-2)); %matrix i
7 x = ones(n(i-2),1); %definition of vector x
8 b = A*x; %definition of vector b
9 P = diag(diag(A)); %diagonal of A as preconditioner
10 tic
11 [x,err,niterJ(i-2)] = richardson stat(A,b,P,1,1e-3,50000); %iteration
12 tel J(i-2) = toc;
13 end
14 9. %Gauss-Seidel method
1
tel GS = zeros(40,1); %initializing variables niterGS = zeros(40,1); %n has already been calculated for i=3:42 G = delsq(numgrid('S',i)); k = 0.01; A = G+k*eye(n(i-2)); %matrix i x = ones(n(i-2),1); %definition of vector x b = A*x; %definition of vector b P = tril(A); %triangular lower A as preconditioner tic [x,err,niterGS(i-2)] = richardson_stat(A,b,P,1,1e-3,50000); %iteration tel GS(i-2) = toc; end