Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following questions refer to the function mfile shown below. I recommend you

ID: 2088746 • Letter: T

Question

The following questions refer to the function mfile shown below. I recommend you try to answer all the questions by "executing" the function manually with calculator/paper/pencil rather than running the code in MATLAB. This is a good way to make sure you understand how the code is executing. 1 function [series_vector, series_sums]-geom2 (n) %[series vector , series sums] -geom2(N) 2 3 %outputs a vector of the first N terms of the geometric series given by Also outputs a second vector of the first N series sums 10-series vector0.5ones (1,N); 11series sums -series vector; 12-for k-2:N 13- 14- 15 series vector (k) = 1/2^k; series_sums (k) - series_sums (k-1)+series_vector (k); end

Explanation / Answer

After the lines 10 and 11 are executed, both series_vector and series_sums are vectors of size 1*N with values 0.5 at every element.

For the first time when line 13 is executed, k = 2. Therefore, 2nd element of series_vector is 1/22 = 1/4. => series_vector(2) = 1/4. And,

series_sums(2) = series_sums(2-1)+series_vector(2) = series_sums(1)+series_vector(2);

=>series_sums(2) = 0.5+1/4 = 0.75

Then the loop is executed again:

This time when line 13 is executed, k = 3. Therefore, 3rd element of series_vector is 1/23 = 1/8. => series_vector(3) = 1/8. At this point, this element is also the minimum value of all the elements in series_vector.

Therefore, the minimum value of series_vector after line 13 is executed is 0.1250.

And,

series_sums(3) = series_sums(3-1)+series_vector(3) =  series_sums(2)+series_vector(3)

=>series_sums(3) = 0.75+1/8 = 0.875

Then the loop is executed again:

This time when line 13 is executed, k = 4. Therefore, 4th element of series_vector is 1/24 = 1/16. => series_vector(4) = 1/16. And,

series_sums(4) = series_sums(4-1)+series_vector(4) =  series_sums(3)+series_vector(4)

=>series_sums(4) = 0.875+1/16 = 0.9375

At this point, this element is also the maximum value of all the elements in series_sums.

Therefore, the maximum value of series_sums when k = 4 is executed is 0.9375.