1. Engineering
  2. Computer Science
  3. a matlab question which need to modify the code and...

Question: a matlab question which need to modify the code and...

Question details

A Matlab question, which need to modify the code and answer it, thanks!

Modify the script to collect average solve times over a range of matrix sizes Ne, for all three of the above described matrix classes. However, we expect that solve times for a smaller matrix should be faster, therefore a larger Nez is needed to get the measured time above tic and tocs range of accuracy. Likewise, different types of matrices may require more or less Ne than others. The takeaway: using the same Nea for all sizes and types of matrix is poor experimental design.

% experimental parameters
N = 1000;
Nex = 50;

% three matrix types

% dense matrix (no zeros)
Md = randn(N,N);

% upper triangular
Mt = triu(Md);

% randomly row-exchanged upper triangular (these are tricky array commands,
% but if you run a small sample, it is clear they do the right thing)
Mp = Mt(idx,:);

% exact solution of all ones
x = ones(N,1);

% right-side vectors
bd = Md*x;
bt = Mt*x;
bp = bt(idx);

% dense test
for jj = 1:Nex
xd = Mdd;

% upper tri test
for jj = 1:Nex
xt = Mtt;

% permuted upper tri test
for jj = 1:Nex
xp = Mpp;

%Computing avgerage solve times
avg_tri_time = tri_time/(Nex);

avg_perm_time = perm_tri_time/(Nex);

avg_dense_time = dense_time/(Nex);

% You may find the following code helpful for displaying the results 
% of this demo.
type_times = {'Dense',avg_dense_time,'Upper Triangular', ...
              avg_tri_time,'permuted Upper Triangular', ...
fprintf('Estimated time for a %s matrix is %f seconds. 
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution