Advertisement
ogiorgil

bs_tester()

Oct 9th, 2022
1,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.98 KB | None | 0 0
  1. function bs_tester()
  2.   N = [10, 30, 50, 70, 100, 300, 500, 700, 1000];
  3.   D = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3];
  4.  
  5.   for n = N
  6.     for d = D
  7.       data_count = d * n * n;
  8.       if data_count < n
  9.         display("impossible to create invertible matrix");
  10.         display(n);
  11.         display(d);
  12.         display("");
  13.         continue;
  14.       endif
  15.       A = sprand(n, n, d);
  16.       A = full(A);
  17.       A = triu(A);
  18.       A = A + eye(n); % Make sure matrix is invertible
  19.       [cidx, ridx, data] = full_to_csr(A);
  20.       x = rand(n, 1);
  21.       b = A * x;
  22.  
  23.       tic();
  24.       x_sparse = sparse_backsub(cidx, ridx, data, b);
  25.       elapsed_time = toc();
  26.  
  27.       tic();
  28.       x_full = backward_substitution(A, b);
  29.       full_elapsed_time = toc();
  30.  
  31.       display(norm(x - x_sparse));
  32.       display(n);
  33.       display(d);
  34.       display(elapsed_time);
  35.       display(full_elapsed_time);
  36.       display(full_elapsed_time - elapsed_time);
  37.       display("");
  38.     endfor
  39.   endfor
  40.  
  41. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement