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

Write and test the code for the function mystery Function that consumes a vector

ID: 3571310 • Letter: W

Question

Write and test the code for the function mystery Function that consumes a vector, V, and produces a new vector, W, of the same length where each element of W is the sum of the corresponding element in V and the previous element of V. Consider the previous element of V(l) to be 0. For example, mystery Function(1:8) should return [1 3 5 7 9 11 13 15] and mystery Function([1: 6].^2) should return [1 5 13 25 41 61] Answer: % function filename: >> mystery Function(l:8) >> mystery Function([l:6].^2)

Explanation / Answer

Executable Code :

% Logic for function

function w = mysteryFunction

w=v

sum=0;

for i=1:length

w(i)=sum+v(i);

sum=v(i);

end

return w;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote