Question #63837

Write a function seqSum(a, N) that returns the sum of the sequence of a, a/2, a/3, ..., a/N where a and N are integers. The function should return the value of a + a/2 + a/3 + ... + a/N. You are not allowed to use “for” or “while” loop for this problem.

Hint: create array(s) and then perform the summation.
1

Expert's answer

2016-12-11T04:50:11-0500

Answer on Question #63837, Programming & Computer Science / MatLAB | Mathematica | MathCAD | Maple

Write a function seqSum(a, N) that returns the sum of the sequence of a, a/2, a/3, ..., a/N where a and N are integers. The function should return the value of a + a/2 + a/3 + ... + a/N. You are not allowed to use "for" or "while" loop for this problem.

Solution:


function S = seqSum(a, N)
numerator = a*ones(1, N);
denominator = 1:N;
S = sum(numerator./denominator);
end


Output:


>> seqSum(2, 4)
ans =
4.1667
>> seqSum(5, 40)
ans =
21.3927


http://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS