Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5 RMS Average The root-mean-square (rms) average is another way of calculating a

ID: 651230 • Letter: 5

Question

5 RMS Average The root-mean-square (rms) average is another way of calculating a mean for a set of numbers. The rms average of a series of numbers is the square root of the arithmetic mean of the squares of the numbers: Write a MATLAB program that will accept an arbitrary number of positive input values and calculate the rms average of the numbers. Prompt the user for the number of values to be entered and use a for loop to read in the numbers. Test your program by calculating the rms average of the four numbers 10, 5, 2, and 5.

Explanation / Answer

%  Script file: rms_average.m
%
%  Purpose:
%    To calculate the rms average of a set of numbers.
%
% Define variables:
%   nvals -- Number of inout values
%   rms   -- Rms average
%   sum2  -- Sum of input values squared
%   x     -- Input values

% Initialize sum
sum2 = 0;

% Read the number of input values
nvals = input('Enter number of values: ');

% Read the numbers
for ii = 1:nvals
   x = input('Enter number:  ');
   sum2 = sum2 + x^2;
end

% Calculate rms average
rms = sqrt( sum2 / nvals );

% Tell user
fprintf('The rms average is %.4f ',rms);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote