Calculate and return the sum of the geometric


To complete this homework assignment, turn in m-files containing the MATLAB code that you generate in response to each problem. Functions should be turned in in separate files. A single script m-file should be turned in. This file should include all scripts that you generate in response  to the problems. In cases where you generate a function in response to the problem, the script fileshould call  this function to demonstrate that it works. Use comments in the script file to indicate which problem each portion of the file is responding to.
1. Write a function repvec that receives a vector and the number of times each element is to be duplicated. The function should then return the resulting vector. Here are some examples of calling the function:

>>repvec(5:-1:1,2)
>>repvec([0 1 0],3)
2. Vectorize the following code:
n = 3;
x = zeros(n);
y = x;
for i = 1:n
x(:,i) = i;
y(i,:) = i;
end
3. Using vectorized code, write a function called geomser that will receive values of r and n and will calculate and return the sum of the geometric series:
1 + r + r2 + r3 + ... + rn
The following examples of calls to this function illustrate what the result should be:
>>geomser(1,5)
>>geomser(2,4)

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Calculate and return the sum of the geometric
Reference No:- TGS01132345

Now Priced at $15 (50% Discount)

Recommended (93%)

Rated (4.5/5)