Rev | Line | |
---|
[37] | 1 | [dummy,T] = lu(rand(5));
|
---|
| 2 | b = rand(5,1);
|
---|
| 3 | fprintf('The columns should be equal:\n');
|
---|
| 4 | [solve_triu(T,b) T\b]
|
---|
| 5 | [solve_tril(T',b) T'\b]
|
---|
| 6 |
|
---|
| 7 | d = 100;
|
---|
| 8 | niter = (20000/d)^2;
|
---|
| 9 | A = rand(d);
|
---|
| 10 | [dummy,T] = lu(A);
|
---|
| 11 | b = rand(d,1);
|
---|
| 12 | tic; for i = 1:niter T\b; end; t1=toc/niter;
|
---|
| 13 | tic; for i = 1:niter solve_triu(T,b); end; t2=toc/niter;
|
---|
| 14 | fprintf('backslash: \t%g\nsolve_triu: \t%g (%g times faster)\n',t1,t2,t1/t2);
|
---|
| 15 | % backslash is detecting triangularity as a preprocessing step, which doubles
|
---|
| 16 | % the time.
|
---|
| 17 | %fprintf('by flops, should be %g times faster\n',...
|
---|
| 18 | % flops_solve(T,b)/flops_solve_tri(T,b));
|
---|
| 19 |
|
---|
| 20 | niter = ceil(niter/d);
|
---|
| 21 | tic; for i = 1:niter inv(T); end; t1=toc/niter;
|
---|
| 22 | %I = eye(size(T));
|
---|
| 23 | %tic; for i = 1:niter solve_triu(T,I); end; t2=toc;
|
---|
| 24 | tic; for i = 1:niter inv_triu(T); end; t2=toc/niter;
|
---|
| 25 | fprintf('inv: \t%g\ninv_triu: \t%g (%g times faster)\n',t1,t2,t1/t2);
|
---|
| 26 | fprintf('by flops, should be %g times faster\n',...
|
---|
| 27 | flops_inv(rows(T))/flops_solve_tri(T,eye(size(T))));
|
---|
Note: See
TracBrowser
for help on using the repository browser.