Calculating sum of elements. The following script computes the element-by-element sum of array y in two ways. The first uses a for loop, while the second uses the Matlab sum function. Find the error in the script.

y = 0:10;
sumY = 0;
for i=0:length(y)-1

sumY = sumY + y(i);
end
sumY
sum(y)


Solution
y = 0:10;
sumY = 0;
for i=1:length(y)

% <-

sumY = sumY + y(i);
end
sumY
sum(y)

Trades & Technology

You might also like to view...

How thick is Item 3?

Refer to Drawing Number 09022601 REV D.

Trades & Technology

List and then explain the two types of veneer walls.

What will be an ideal response?

Trades & Technology

Which Roman emperor prohibited the practice of paganism and ordered all pagan temples closed?

a. Julian b. Constantine c. Theodosius d. Valerian

Trades & Technology

Technician A says that all electrons are alike regardless of the atomic element? Technician B says that all protons are alike regardless of the atomic element? Who is correct?

A. Technician A only B. Technician B only C. Both A and B D. Neither A nor B

Trades & Technology