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

Function Name: recurSum Inputs (1): - (double) A 1xN array ofscalars Outputs (1)

ID: 3617337 • Letter: F

Question

Function Name: recurSum Inputs (1): - (double) A 1xN array ofscalars Outputs (1): - (double) The sum of the elements of theinput array
Function Description: Given a 1xN array of scalars (a vector), write a functionrecurSum that    recursively sums the elements of the input array.Your function should    then return this sum. An empty vector ([])has a sum of 0.
Constraints: You MUST use recursion to solve this problem.
Hints: This function should behave like the built in MATLAB functionsum().
Test Cases:
   a = recurSum([12 -3 0 17 25 62 34]);    a => 147
b = recurSum([]); b => 0; Function Name: recurSum Inputs (1): - (double) A 1xN array ofscalars Outputs (1): - (double) The sum of the elements of theinput array
Function Description: Given a 1xN array of scalars (a vector), write a functionrecurSum that    recursively sums the elements of the input array.Your function should    then return this sum. An empty vector ([])has a sum of 0.
Constraints: You MUST use recursion to solve this problem.
Hints: This function should behave like the built in MATLAB functionsum().
Test Cases:
   a = recurSum([12 -3 0 17 25 62 34]);    a => 147
b = recurSum([]); b => 0;

Explanation / Answer

function A= recurSum(B) [m n]=size(B); %you can add error checking to make sure m=1 if youwant if(n>0)     A=B(1,1)+recurSum(B(1,2:end)); else     A=0; end