122k views
2 votes
Write a function file that accepts the values of r, a and n as arguments and uses a for loop to return the sum of the first n terms of the geometric series. test your function for a = 3, r = 1/2 and n = 10.

User Only You
by
5.6k points

1 Answer

7 votes

Given, a = 3, r = 1/2, n = 10

%r is common ratio

%n is number of terms

%a is the first term of the series

Sum = 0;

a = 3;

r = 1/2;

for i = 0 : 1 : 10;

Sum = Sum + a * r ^ i;

end

Sum


User Eric Baldwin
by
5.5k points