Question: Matlab Code % The following code is run in the Command Window. List the value of % tot at the end of each iteration as

Matlab Code

% The following code is run in the Command Window. List the value of % "tot" at the end of each iteration as a seperate element in a vector. % % For example, if "tot" is 3 at the end of the first iteration, % 5 after the second and 10 after the third, then your answer should % read E = [3, 5, 10];

vec = [2, 10, -8, 2, 0, 0, 5]; idx = 1; prev = NaN; curr = vec(idx); tot = 0; while prev ~= curr idx = idx + 1; prev = curr; curr = vec(idx); if prev < curr tot = tot + curr; end end

% 3. The value of "tot" after each iteration is (E): E =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!