1 / 15

Scientific Computing Lab

Scientific Computing in Computer Science. Institut für Informatik. Scientific Computing Lab. Results Worksheet 3. Dr. Miriam Mehl. Worksheet 3 – Solution. N x = N y =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;

Download Presentation

Scientific Computing Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Worksheet 3 – Solution Nx= Ny=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 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 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 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 Nx= Ny=7

  9. Worksheet 3 – Solution Nx= Ny=15

  10. Worksheet 3 – Solution Nx= Ny=31

  11. Worksheet 3 – Solution Nx= Ny=63

  12. Worksheet 3 – Solution direct solution with full matrix

  13. Worksheet 3 – Solution direct solution with sparse matrix

  14. Worksheet 3 – Solution Gauss-Seidel without explicit matrix

  15. Worksheet 3 – Solution error – convergence order q=2

More Related