
Concept explainers
To write:
A

Answer to Problem 10.1P
Solution:
The function file is,
%MATLAB code to create a function that will receive a value for r and calculate and return the sum of the geometric series and if a second argument is passed to the function, then the function generates a random integer for n.
%function file
function sum = geomser(r, varargin)
%define the function geomser.
arg = nargin;
if arg == 2
%if arguments are two then it will generate proper sum.
n = varargin{1};
%if only second argument is present then it will take a random integer
%for n.
else
n = randi([5, 30]);
end
s = 1;
for j = 1:n
s = s + r.^j;
end
sum = s;
end
%end of function file
%The function file should be placed in the same folder.
Explanation of Solution
The formula for to calculate the sum of a geometric series is given as,
Substitute 3 for r and 5 for n in the above formula.
MATLAB Code:
%MATLAB code to create a function that will receive a value for r and calculate and return the sum of the geometric series and if a second argument is passed to the function, then the function generates a random integer for n.
%function file
function sum = geomser(r, varargin)
%define the function geomser.
arg = nargin;
if arg == 2
%if arguments are two then it will generate proper sum.
n = varargin{1};
%if only second argument is present then it will take a random integer
%for n.
else
n = randi([5, 30]);
end
s = 1;
for j = 1:n
s = s + r.^j;
end
sum = s;
end
%end of function file
%The function file should be placed in the same folder.
Save the MATLAB function with name, geomser.m in the current folder. Execute the function file by typing the function name at the command window to generate output.
Result:
The result is,
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 10 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Clint, obviously not in college, sleeps an average of 8 hours per night with a standard deviation of 15 minutes. What's the chance of him sleeping between 7.5 and 8.5 hours on any given night? 0-(7-0) 200 91109s and doiw $20 (8-0) mol 8520 slang $199 galbrog seam side pide & D (newid se od poyesvig as PELEO PER AFTE editiw noudab temand van Czarrow_forwardTimes to complete a statistics exam have a normal distribution with a mean of 40 minutes and standard deviation of 6 minutes. Deshawn's time comes in at the 90th percentile. What percentage of the students are still working on their exams when Deshawn leaves?arrow_forwardSuppose that the weights of cereal boxes have a normal distribution with a mean of 20 ounces and standard deviation of half an ounce. A box that has a standard score of o weighs how much? syed by ilog ni 21arrow_forward
- Bob scores 80 on both his math exam (which has a mean of 70 and standard deviation of 10) and his English exam (which has a mean of 85 and standard deviation of 5). Find and interpret Bob's Z-scores on both exams to let him know which exam (if either) he did bet- ter on. Don't, however, let his parents know; let them think he's just as good at both subjects. algas 70) sering digarrow_forwardSue's math class exam has a mean of 70 with a standard deviation of 5. Her standard score is-2. What's her original exam score?arrow_forwardClint sleeps an average of 8 hours per night with a standard deviation of 15 minutes. What's the chance he will sleep less than 7.5 hours tonight? nut bow visarrow_forward
- Suppose that your score on an exam is directly at the mean. What's your standard score?arrow_forwardOne state's annual rainfall has a normal dis- tribution with a mean of 100 inches and standard deviation of 25 inches. Suppose that corn grows best when the annual rainfall is between 100 and 150 inches. What's the chance of achieving this amount of rainfall? wved now of sociarrow_forward13 Suppose that your exam score has a standard score of 0.90. Does this mean that 90 percent of the other exam scores are lower than yours?arrow_forward
- Bob's commuting times to work have a nor- mal distribution with a mean of 45 minutes and standard deviation of 10 minutes. How often does Bob get to work in 30 to 45 minutes?arrow_forwardBob's commuting times to work have a nor- mal distribution with a mean of 45 minutes and standard deviation of 10 minutes. a. What percentage of the time does Bob get to work in 30 minutes or less? b. Bob's workday starts at 9 a.m. If he leaves at 8 a.m., how often is he late?arrow_forwardSuppose that you want to put fat Fido on a weight-loss program. Before the program, his weight had a standard score of +2 com- pared to dogs of his breed/age, and after the program, his weight has a standard score of -2. His weight before the program was 150 pounds, and the standard deviation for the breed is 5 pounds. a. What's the mean weight for Fido's breed/ age? b. What's his weight after the weight-loss program?arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage