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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started