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);
endOutput:
>> seqSum(2, 4)
ans =
4.1667
>> seqSum(5, 40)
ans =
21.3927http://www.AssignmentExpert.com
Comments