Download presentation
Presentation is loading. Please wait.
Published byArron Wilkinson Modified over 9 years ago
1
Numerical method1 Iterative approaches for solving linear systems Successive over-relaxation Post-nonlinear system Partial pivoting Lecture 11-II
2
Numerical method2 Derivation of Successive over- relaxation
3
Numerical method3 Successive over-relaxation method D=diag(diag(A)); U=triu(A)-D; L=A-triu(A); R=D+w*L; T=inv(R)*((1-w)*D-w*U); c=w*inv(R)*b;
4
Numerical method4 Successive over-relaxation method A,b it_xor.m x A=[10 -1 2 0;-1 11 -1 3; 2 -1 10 -1;0 3 -1 8]; b=[6 25 -11 15] ' ; inv(A)*b
5
Numerical method5 >> it_xor(A,b) It takes 17 iterations to converge ans = 1.00000000300255 2.00000000357295 -1.00000000163021 0.99999999724547
6
Numerical method6 Variant successive over- relaxation
7
Numerical method7 Variant Successive over- relaxation D=diag(diag(A)); U=triu(A)-D; L=A-triu(A); R=w*D+D+L; T=inv(R)*(w*D-U); c=inv(R)*b;
8
Numerical method8 Variant Successive over- relaxation method A,b it_vxor.m x A=[10 -1 2 0;-1 11 -1 3; 2 -1 10 -1;0 3 -1 8]; b=[6 25 -11 15] ' ; inv(A)*b
9
Numerical method9 >> it_vxor(A,b,w) It takes 17 iterations to converge ans = 1.00000000300255 2.00000000357295 -1.00000000163021 0.99999999724547
10
Numerical method10 w=0 >> it_vxor(A,b,0) It takes 10 iterations to converge ans = 0.99999999998681 1.99999999985957 -0.99999999997639 1.00000000005561
11
Numerical method11 Large w >> it_vxor(A,b,3) It takes 90 iterations to converge ans = 0.99999998371358 1.99999997234472 -0.99999998858309 1.00000003116601
12
Numerical method12 Post-Nonlinear System Ax=b, A=rand(100,100),b=rand(100,1) Ax=b, A=rand(100,100),b=rand(100,1) f(Ax)=b, where f is an arbitrary one- dimensional nonlinear function f(Ax)=b, where f is an arbitrary one- dimensional nonlinear function Given A,b Given A,b find f and x find f and x
13
Numerical method13 f(Ax)=b Multiple solutions Multiple solutions x f mean absolute error: 0.017080 mean square error: 0.000755 mean(abs(b-f(Ax)))
14
Numerical method14 f(Ax)=b Multiple solutions Multiple solutions x f mean absolute error: 0.024637 mean square error: 0.002738
15
Numerical method15 Matrix inversion Solve Gx=f Solve Gx=f Example Example Gf.zip >> load Gf.mat; >> inv(G); Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.206041e-017.
16
Numerical method16 rank ss=cputime; for i=1:1000 rank(G); end ss2=cputime; fprintf('cputime: rank %f \n',ss2-ss); cputime: rank 1.703125
17
Numerical method17 rank ss=cputime; for i=1:50000 rank(G); end ss2=cputime; fprintf('cputime: rank %f \n',ss2-ss); cputime: rank 82.546875
18
Numerical method18 pinv ss=cputime; for i=1:1000 pinv(G); end ss2=cputime; fprintf('cputime: pinv %f \n',ss2-ss); cputime: pinv 7.062500
19
Numerical method19 Inverse of submatrix ss=cputime; for i=1:50000 inv(G(1:61,1:61)); end ss2=cputime; fprintf('cputime: pinv %f \n',ss2-ss); cputime: inv of submatrix 28.937500 Time reduced from 50*7.06 to 28.93 sec
20
Numerical method20 Partial pivoting Maximal column pivoting Maximal column pivoting The pivot or pivot element is the element of a matrix, which is selected first by anmatrix algorithmalgorithm (e.g. Gaussian elimination, Quicksort, Simplex algorithm),Gaussian eliminationQuicksortSimplex algorithm to do certain calculations with the matrix
21
Numerical method21 A=[10.^-16 59.17;5.29 -6.13]; b=[59.17 46.78]'; B=[A b]; fGauss.m backward.m B 0.0 1.0000 ans = 10.0019 1.0000 B=fGauss(B) x=backward(B)
22
Numerical method22 B = 10.^-16 59.1400 59.1700 5.2900 -6.1300 46.7800 Find Exchange row 1 and row 2 temp=B(1,:); B(1,:)=B(2,:); B(2,:)=temp;
23
Numerical method23 U=fGauss(B); x=backward(U) x = 10.0019 1.0000 B = 5.2900 -6.1300 46.7800 10.^-16 59.1400 59.1700
24
Numerical method24 A=[30.00 591400;5.29 -6.13]; b=[591700 46.78]'; B=[A b];
25
Numerical method25 Scaled partial pivoting Exchange row i and row p
26
Numerical method26 A = 2.1100 -4.2100 0.9210 4.0100 10.2000 -1.1200 1.0900 0.9870 0.8320 Determine the first pivot by [v p]=max(A(:,1)./s); >> s=max(abs(A'))' s = 4.2100 10.2000 1.0900 p = 3
27
Numerical method27 Scaled partial pivoting Scaled partial pivoting Function [B,pr]=pss(A,b) n=length(b);B=[A b]; pr=[]; n=length(b);B=[A b]; pr=[]; s=max(abs(A'))'Pr=1:n; for i= 1:n A.Find the ith pivot row and set it to p B.Exchange pr(i) and pr(p) C.Exchange row i and row p of matrix B D.For each row j > i 1)Set d to the ratio B(j,i) / B(i,i) 2)Set B(j,:) to B(j,:)-d*B(i,:) Return B and pr
28
Numerical method28 Example A=[2.11 -4.21.921;4.01 10.2 -1.12;1.09.987.832]; b=[2.01 -3.09 4.21]'; spp.m [B,pr]=spp(A,b) B = 1.0900 0.9870 0.8320 4.2100 0 -6.1206 -0.6896 -6.1396 0 0.0000 -4.9209 -25.1675 pr = 3 1 2
29
Numerical method29 Example A=[1.19 2.11 -100 1;14.2 -0.122 12.2 -1;0 100 -99.9 1; 15.3 0.110 -13.1 -1]; b=[1.12 3.44 2.15 4.16]'; [B,pr]=spp(A,b); x=backward(B); x = 0.1768 0.0127 -0.0207 -1.1826
30
Numerical method30 Exercise Implement the scaled partial pivoting method to improve the forward Gauss elimination method. Implement the scaled partial pivoting method to improve the forward Gauss elimination method. Verify your matlab codes by two examples Verify your matlab codes by two examples
31
Numerical method31 Avoid row swapping Row swapping results in time consuming Row swapping results in time consuming No row swapping No row swapping Use a vector v to emulate row swapping Use a vector v to emulate row swapping Swap elements in v instead of swapping rows in B Swap elements in v instead of swapping rows in B How to revise spp.m to avoid row swapping ? How to revise spp.m to avoid row swapping ?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.