The geometric mean of a set of positive numbers x, through x, is defined as the nth root of the product of the numbers: (eq) geometric mean = Vx,x,X3..., Write a MATLAB program that will accept arbitrary number of positive input values and calculate the arithmetic mean (i.e., the avarage) and the geometric mean of the numbers. Use a while loop to get the input values, and terminate the inputs when a user enters a negative number. Test your program by calculating the average and geometric mean of the four numbers 10, 5, 2, and 5.
The geometric mean of a set of positive numbers x, through x, is defined as the nth root of the product of the numbers: (eq) geometric mean = Vx,x,X3..., Write a MATLAB program that will accept arbitrary number of positive input values and calculate the arithmetic mean (i.e., the avarage) and the geometric mean of the numbers. Use a while loop to get the input values, and terminate the inputs when a user enters a negative number. Test your program by calculating the average and geometric mean of the four numbers 10, 5, 2, and 5.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![The geometric mean of a set of positive numbers x through x, is defined as the nth root of the product of the numbers:
(eq) geometric mean = Vxx,xz.
Write a MATLAB program that will accept arbitrary number of positive input values and calculate the arithmetic mean (i.e., the avarage) and the geometric mean of the numbers.
Use a while loop to get the input values, and terminate the inputs when a user enters a negative number. Test your program by calculating the average and geometric mean of the
four numbers 10, 5, 2, and 5.
Script e
A Save
C Reset
I MATLAB Documentation
1 % Define variables:
-- Input values
-- Geometric mean
2 % x
% g
4 % nvals -- Number of input values
5 % prod
6 % Initialize product and nvals
7 i = 1;
-- Product of input values
8
10 % Simulate User Input
11 % Read the first number
12 sampleData = [10 5 2 5 -1];
13 x = sampleData(1,1);
14 disp(strcat('Enter first number: ',int2str(x)));
15 % Read the remaining numbers
16
17
18
% Simulate User Input starting 2nd element of the sampleData
19
20
21
22
23
24 % Calculate geometric mean
25
26 % Tell user
27 fprintf(' The geometric mean is %.4f\n',g);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff06f71ad-29ec-436e-9181-a7dade001792%2F7e664625-e2e7-4d45-b5e5-cdfcd431b3ae%2Fxtr402j_processed.png&w=3840&q=75)
Transcribed Image Text:The geometric mean of a set of positive numbers x through x, is defined as the nth root of the product of the numbers:
(eq) geometric mean = Vxx,xz.
Write a MATLAB program that will accept arbitrary number of positive input values and calculate the arithmetic mean (i.e., the avarage) and the geometric mean of the numbers.
Use a while loop to get the input values, and terminate the inputs when a user enters a negative number. Test your program by calculating the average and geometric mean of the
four numbers 10, 5, 2, and 5.
Script e
A Save
C Reset
I MATLAB Documentation
1 % Define variables:
-- Input values
-- Geometric mean
2 % x
% g
4 % nvals -- Number of input values
5 % prod
6 % Initialize product and nvals
7 i = 1;
-- Product of input values
8
10 % Simulate User Input
11 % Read the first number
12 sampleData = [10 5 2 5 -1];
13 x = sampleData(1,1);
14 disp(strcat('Enter first number: ',int2str(x)));
15 % Read the remaining numbers
16
17
18
% Simulate User Input starting 2nd element of the sampleData
19
20
21
22
23
24 % Calculate geometric mean
25
26 % Tell user
27 fprintf(' The geometric mean is %.4f\n',g);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY