FOR Loops in MATLAB to Determine Values

$29.00$19.001144 reads

Question

For the following for loop:

x = [4 8 2.1 3 9 7 1];

c = 0;

for k = 1:2:length(x)-2

if x(k) + x(k+1) > c

c = x(k) + x(k+1);

end

end

a) How many times does the for loop loop?

b) What are the values that k takes on in the loop? Ie, first time through the for loop k is --‐, second time through k is -, etc.

c)  What is the value of c after the for loop ends?

Summary

This question belongs to MATLAB software and discusses about FOR loops and to compute value of the given equation.   

Answer is in MATLAB format

 

Add to Cart