MATLAB: A Practical Introduction to Programming and Problem Solving
MATLAB: A Practical Introduction to Programming and Problem Solving
5th Edition
ISBN: 9780128154793
Author: Stormy Attaway Ph.D. Boston University
Publisher: Elsevier Science
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 10, Problem 10.1P
To determine

To write:

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.

Expert Solution & Answer
Check Mark

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,

S=1+r+r2+r3+r4+...+rn

Substitute 3 for r and 5 for n in the above formula.

S=1+(3)+(3)2+(3)3+(3)4+(3)5S=364

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,

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 10, Problem 10.1P

Therefore, the result is stated above.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
In order to find probability, you can use this formula in Microsoft Excel: The best way to understand and solve these problems is by first drawing a bell curve and marking key points such as x, the mean, and the areas of interest. Once marked on the bell curve, figure out what calculations are needed to find the area of interest. =NORM.DIST(x, Mean, Standard Dev., TRUE). When the question mentions “greater than” you may have to subtract your answer from 1. When the question mentions “between (two values)”, you need to do separate calculation for both values and then subtract their results to get the answer. 1.  Compute the probability of a value between 44.0 and 55.0. (The question requires finding probability value between 44 and 55. Solve it in 3 steps. In the first step, use the above formula and x = 44, calculate probability value. In the second step repeat the first step with the only difference that x=55. In the third step, subtract the answer of the first part from the…
If a uniform distribution is defined over the interval from 6 to 10, then answer the followings: What is the mean of this uniform distribution? Show that the probability of any value between 6 and 10 is equal to 1.0 Find the probability of a value more than 7. Find the probability of a value between 7 and 9.   The closing price of Schnur Sporting Goods Inc. common stock is uniformly distributed between $20 and $30 per share. What is the probability that the stock price will be: More than $27? Less than or equal to $24?   The April rainfall in Flagstaff, Arizona, follows a uniform distribution between 0.5 and 3.00 inches. What is the mean amount of rainfall for the month? What is the probability of less than an inch of rain for the month? What is the probability of exactly 1.00 inch of rain? What is the probability of more than 1.50 inches of rain for the month? The best way to solve this problem is begin by creating a chart. Clearly mark the range, identifying the lower and upper…
Problem 1: The mean hourly pay of an American Airlines flight attendant is normally distributed with a mean of 40 per hour and a standard deviation of 3.00 per hour. What is the probability that the hourly pay of a randomly selected flight attendant is: Between the mean and $45 per hour? More than $45 per hour? Less than $32 per hour?   Problem 2: The mean of a normal probability distribution is 400 pounds. The standard deviation is 10 pounds. What is the area between 415 pounds and the mean of 400 pounds? What is the area between the mean and 395 pounds? What is the probability of randomly selecting a value less than 395 pounds?   Problem 3: In New York State, the mean salary for high school teachers in 2022 was 81,410 with a standard deviation of 9,500. Only Alaska’s mean salary was higher. Assume New York’s state salaries follow a normal distribution. What percent of New York State high school teachers earn between 70,000 and 75,000? What percent of New York State high school…
Knowledge Booster
Background pattern image
Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, statistics and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Sequences and Series Introduction; Author: Mario's Math Tutoring;https://www.youtube.com/watch?v=m5Yn4BdpOV0;License: Standard YouTube License, CC-BY
Introduction to sequences; Author: Dr. Trefor Bazett;https://www.youtube.com/watch?v=VG9ft4_dK24;License: Standard YouTube License, CC-BY