Respuesta :
Answer:
For n = 100
- (AB)x: 10100
- A(Bx): 200
For n = 200
- (AB)x: 40200
- A(Bx): 400
For n = 400
- (AB)x: 160400
- A(Bx): 800
For n = 800
- (AB)x: 640800
- A(Bx): 1600
The faster approach is A(Bx)
Explanation step by step functions:
A(Bx) is faster because requires fewer interactions to find a result: for (AB)x you have (n*n)+n interactions while for A(Bx) you have n+n, to understand why please see the step by step:
a) Function for (AB)x:
function loopcount1 = FirstAB(A,B,x)
n = size(A)(1);
AB = zeros(n,n);
ABx = zeros(n,1);
loopcount1 = 0;
for i = 1:n
for j = 1:n
AB(i,j) = A(i,:)*B(:,j);
loopcount1 += 1;
end
end
for k = 1:n
ABx(k) = AB(k,:)*x;
loopcount1 += 1;
end
end
b) Function for A(Bx):
function loopcount2 = FirstBx(A,B,x)
n = size(A)(1);
Bx = zeros(n,1);
ABx = zeros(n,1);
loopcount2 = 0;
for i = 1:n
Bx(i) = B(i,:)*x;
loopcount2 += 1;
end
for j = 1:n
ABx(j) = A(j,:)*Bx;
loopcount2 += 1;
end
end
In this exercise we want to use computer and python knowledge to write the code correctly, so it is necessary to add the following to the informed code:
The correct code that corresponds to the question informed is attached in the photo and we can notice that the faster approach is A(Bx).
So knowing that the information given in the text is that;
For n = 100:
- (AB)x: 10100
- A(Bx): 200
For n = 200:
- (AB)x: 40200
- A(Bx): 400
For n = 400:
- (AB)x: 160400
- A(Bx): 800
For n = 800:
- (AB)x: 640800
- A(Bx): 1600
A(Bx) exist faster cause demand hardly any interplay to find a result: for (AB)x you bear (n*n)+n interplay while for A(Bx) you bear n+n, so we have that:
a)Watching the function for (AB)x:
function loopcount1 = FirstAB(A,B,x)
n = size(A)(1);
AB = zeros(n,n);
ABx = zeros(n,1);
loopcount1 = 0;
for i = 1:n
for j = 1:n
AB(i,j) = A(i,:)*B(:,j);
loopcount1 += 1;
end
end
for k = 1:n
ABx(k) = AB(k,:)*x;
loopcount1 += 1;
end
end
b) Watching the function for A(Bx):
function loopcount2 = FirstBx(A,B,x)
n = size(A)(1);
Bx = zeros(n,1);
ABx = zeros(n,1);
loopcount2 = 0;
for i = 1:n
Bx(i) = B(i,:)*x;
loopcount2 += 1;
end
for j = 1:n
ABx(j) = A(j,:)*Bx;
loopcount2 += 1;
end
end
See more about computer at brainly.com/question/950632

