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
- what is the correct answer and why?arrow_forward(a) How many bit strings of length 10 both begin with a 1 and end with 2 zeroes? (b) How many permutations of the letters PQRSTUV contain PRS and QV?arrow_forward(d) A clothing store sells red, white, green, orange and pink charms for a specialty bracelet. How many ways can a customer purchase a bracelet with (i) 16 charms? (ii) 27 charms with at least 3 of each colour?arrow_forward
- (d) Draw the Venn diagram which represents the set (A U B) U (B NC).arrow_forwardThe ages of undergraduate students at two universities (one in the east and one in the west) are being compared. Researchers want to know if there is a difference in the mean age of students at the two universities. The population standard deviations are known. The following data shows the results of samples collected at each institution: School Location n sample mean population std. dev. West 33 26.78 6.29 East 35 23.16 7.52 What is the value of the test statistic for this problem? what is the p-value? what is the decision (reject or do not reject the null hypothesis?arrow_forwardA common way for two people to settle a frivolous dispute is to play a game of rock-paper-scissors. In this game, each person simultaneously displays a hand signal to indicate a rock, a piece of paper, or a pair of scissors. Rock beats scissors, scissors beats paper, and paper beats rock. If both players select the same hand signal, the game results in a tie. Two roommates, roommate A and roommate B, are expecting company and are arguing over who should have to wash the dishes before the company arrives. Roommate A suggests a game of rock-paper-scissors to settle the dispute. Consider the game of rock-paper-scissors to be an experiment. In the long run, roommate A chooses rock 24% of the time, and roommate B chooses rock 85% of the time; roommate A selects paper 12% of the time, and roommate B selects paper 14% of the time; roommate A chooses scissors 64% of the time, and roommate B chooses scissors 1% of the time. (These choices are made randomly and independently of each…arrow_forward
- Perform the following hypothesis test: HO: µ = 6 H1: µ 6 The sample mean is 5.6, sample standard deviation of 1.5 and a sample size of 42. Use a 5% significance level. Need to answer the following questions: what is the value of the test statistic? what is the p-value for this test (round to 3 decimal places)? what is the decision (reject the null hypothesis or do not reject the null hypothesis)?arrow_forwardPerform the following hypothesis test of a proportion: HO: p = 0.125 HA: p 0.125 The sample proportion is 0.2 based on a sample size of 95. Use a 10% significance level. need to solve the following questions: what is the value of the test statistic? what is the p-value? what is the decision (reject the null hypothesis or do not reject the null hypothesis)?arrow_forwardOOOOOOO00 Let's play Pick-A-Ball with replacement! There are 10 colored balls: 2 red, 4 white, and 4 blue. The balls have been placed into a small bucket, and the bucket has been shaken thoroughly. You will be asked to reach into the bucket, without looking, and select two balls. Since the bucket has been shaken thoroughly, you can assume that each individual ball is selected at random with equal likelihood of being chosen. Now, close your eyes! Reach into the bucket, and pick a ball. (Click the red Pick-A-Ball! icon to select your ball.) Pick-A-Ball! What is the probability of selecting the color of ball that you just selected? (Enter your answer in decimal format and round it to two decimal places.) Assume you have put your first ball back into the bucket. Now, reach in (again, no peeking!), and pick your second ball. (Click the red Pick-A-Ball! icon to select your second ball.) Pick-A-Ball! What is the probability of selecting the color of ball that you just selected? (Enter your…arrow_forward
- There are 10 colored balls: 2 red, 4 white, and 4 blue. The balls have been placed into a small bucket, and the bucket has been shaken thoroughly. You will be asked to reach into the bucket, without looking, and select two balls. Since the bucket has been shaken thoroughly, you can assume that each individual ball is selected at random with likelihood of being chosen. Now, close your eyes! Reach into the bucket, and pick a ball. (Click the red Pick-A-Ball! icon to select your ball.) Pick-A-Ball! What is the probability of selecting the color of ball that you just selected? (Enter your answer in decimal format and round it to two decimal places.) Assume you have put your first ball back into the bucket. Now, reach in (again, no peeking!), and pick your second ball. (Click the red Pick-A-Ball! icon to select your second ball.) Pick-A-Ball! What is the probability of selecting the color of ball that you just selected? (Enter your answer in decimal format and round it to…arrow_forwardConsider a population that consists of the 70 students enrolled in a statistics course at a large university. If the university registrar were to compile the grade point averages (GPAs) of all 70 students in the course and compute their average, the result would be a mean GPA of 2.98. Note that this average is unknown to anyone; to collect the GPA information would violate the confidentiality of the students’ academic records. Suppose that the professor who teaches the course wants to know the mean GPA of the students enrolled in her course. She selects a sample of students who are in attendance on the third day of class. The GPAs of the students in the sample are: 3.71 3.92 3.68 3.60 3.64 3.27 3.93 3.12 3.40 3.74 The instructor uses the sample average as an estimate of the mean GPA of her students. The absolute value of the error in the instructor’s estimate is: 0.62 0.52 0.86 0.80 The portion of this error that is due to errors in data…arrow_forwardThe potential of using solar panels constructed above national highways to generate energy was explored in a particular engineering journal. Two-layer solar panels (with 1 meter separating the panels) were constructed above sections of both east-west and north-south highways in a certain country. The amount of energy (kilowatt-hours) supplied to the country's grid by the solar panels above the two types of highways was determined each month. The data for several randomly selected months are provided in the accompanying table. The researchers concluded that the two-layer solar panel energy generation is more viable for the north-south oriented highways as compared to east-west oriented roadways. Compare the mean solar energy amounts generated for the two types of highways using a 97% confidence interval. Does the interval support the researchers' conclusion? Click the icon to view the data table. Find a 97% confidence interval for μd. Let μd =μ₁₂, where μ₁ is the mean solar energy…arrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage