Why it cannot display flop?
you need to explain rather than just show me another code
MatLab
function b=Matrixvector(A,x)
n=length(x);
b=zeros(n,1);
flop=0;
for i=1:n
for j=1:n
b(i)=b(i)+A(i,j)*x(j);
flop=flop+2;
end
end
disp(b);
disp(flop);
After copying the provided function over to a script file named 'Matrixvector.m'; when the below code is run, the output obtained is shown underneath.
Code:
clc
A = [1 2 1; 5 2 6; 8 9 5];
x = [1 2 3];
b = Matrixvector(A,x); % Calling the function
Output:
8
27
41
18
Explanation: In the output, the first three (for this example) elements are from disp(b) command in the Matrixvector function and the last element is the flop value. The last value will be the value of the flop; and the first three (for this example) only is the vector b.
Note: No change is required in the provided Matrixvector function.
Get Answers For Free
Most questions answered within 1 hours.