Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scientific Computing Lab Results Worksheet 3 Dr. Miriam Mehl Institut für Informatik Scientific Computing in Computer Science.

Similar presentations


Presentation on theme: "Scientific Computing Lab Results Worksheet 3 Dr. Miriam Mehl Institut für Informatik Scientific Computing in Computer Science."— Presentation transcript:

1 Scientific Computing Lab Results Worksheet 3 Dr. Miriam Mehl Institut für Informatik Scientific Computing in Computer Science

2 Worksheet 3 – Solution N x = N y =3

3 Worksheet 3 – Solution 1) m-file create_matrix.m for m=1:N_y for k=1:N_x i = (m-1)*N_x+k; A(i,i) = -2*(N_x+1)^2-2*(N_y+1)^2; if ~(k==1) A(i,i-1) = (N_x+1)^2; end … if ~(m==1) A(i,i-N_x) = (N_y+1)^2; end … end

4 Worksheet 3 – Solution 2) m-file GaussSeidel.m while (res>0.0001) res=0.0; for m=2:N_y+1 for k=2:N_x+1 x_m(k,m)=(d_1*(x_m(k-1,m)+x_m(k+1,m))+… end for m=2:N_y+1 for k=2:N_x+1 res=res+(b((m-2)*N_x+k-1)+a_ii*x_m(k,m)-… end res=sqrt(res/(N_x*N_y)); end

5 Worksheet 3 – Solution 3) m-file worksheet3.m tic; x=A\b; time(1)=toc; memory(1)=numel(A)+numel(b)+numel(x); %transform x to a matrix for visualisation x_m=zeros(N_x+2,N_y+2); for k=2:N_x+1 for m=2:N_y+1 x_m(k,m)=x((m-2)*N_x+k-1); end end … subplot(2,1,1); mesh(coord1,coord2,x_m); subplot(2,1,2);contour(coord1,coord2,x_m);

6 Worksheet 3 – Solution 3) m-file worksheet3.m S=sparse(A); tic; x=S\b; time(2)=toc; memory(2)=nnz(S)+numel(b)+numel(x);

7 Worksheet 3 – Solution 3) m-file worksheet3.m tic; x_m=GaussSeidel(b,N_x,N_y); time(3)=toc memory(3)=numel(b)+numel(x_m)

8 Worksheet 3 – Solution N x = N y =7

9 Worksheet 3 – Solution N x = N y =15

10 Worksheet 3 – Solution N x = N y =31

11 Worksheet 3 – Solution N x = N y =63

12 Worksheet 3 – Solution direct solution with full matrix N x, N y 7153163 runtime0.00020.00440.193610.4078 storage2,49951,075925,44315,760,899

13 Worksheet 3 – Solution direct solution with sparse matrix runtime0.00140.00450.01820.0826 storage3151,5156,60327,531 N x, N y 7153163 runtime0.00020.00440.193610.4078 storage2,49951,075925,44315,760,899

14 Worksheet 3 – Solution Gauss-Seidel without explicit matrix runtime0.00170.01480.18312.7531 storage1305142,0508,194 iterations6927110784305 runtime0.00140.00450.01820.0826 storage3151,5156,60327,531 N x, N y 7153163 runtime0.00020.00440.193610.4078 storage2,49951,075925,44315,760,899

15 Worksheet 3 – Solution error – convergence order N x, N y 153163127 error0.00174.10*10 -4 9.70*10 -5 2.02*10 -5 error red.4.354.144.234.83 q=2


Download ppt "Scientific Computing Lab Results Worksheet 3 Dr. Miriam Mehl Institut für Informatik Scientific Computing in Computer Science."

Similar presentations


Ads by Google