Question: Code in matlab ( 5 points total) The following code computes the average diagonal sum of a n n upper-triangular matrix U. (The diagonals below

Code in matlab ( 5 points total) The following code computes the average diagonal sum of a n n upper-triangular matrix U. (The diagonals below the main diagonal are not included in this computation since their entries all equal zero.)

[n,] = size(U); % U is a given n x n upper-triangular matrix. diagSum = zeros(n,1);

% diagSum is a n x 1 column vector of zeros.

totDiagSum = 0;

for k = 1:n

for i = 1:n-k+1 % Dont include the flops to compute n-k+1.

diagSum(k) = diagSum(k) + U(i,k+i-1); % Dont include the flops to compute k+i-1.

end

totDiagSum = totDiagSum + diagSum(k);

end

avgDiagSum = totDiagSum/n; % avgDiagSum is the average diagonal sum of U.

(a) (3 points) Compute the flop count of the code above. Be sure to exclude the arithmetic operations mentioned in the comments above.

b) (2 points) What is the asymptotic flop count of the code above? For large matrices U, is this code more or less expensive than back substitution?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!