Answer to Question #45547 in MatLAB | Mathematica | MathCAD | Maple for VISHNUJITH

Question #45547
Write a single program that calculates the arithmetic mean (average), rms average, geometric mean and harmonic mean for a set of n positive numbers. Your program should take two values xlow and xhigh and generate 10000 random numbers in the range [xlow…xhigh], and should print out arithmetic mean (average), rms average, geometric mean and harmonic mean.
The definitions of means are given as follows.
1
Expert's answer
2014-09-03T04:21:34-0400
% Input
xlow = input('xlow: ');
xhigh = input('xhigh: ');

% Random array
array = randi([xlow xhigh], 1, 10000);

% Arithmetic mean
AM = mean(array);
% Quadratic mean
QM = sqrt(mean(array.^2));
% Geometric mean
GM = geomean(array);
% Harmonic mean
HM = harmmean(array);

% Output
fprintf('Arithmetic mean: %.3f\n', AM);
fprintf('Quadratic mean: %.3f\n', QM);
fprintf('Geometric mean: %.3f\n', GM);
fprintf('Harmonic mean: %.3f\n', HM);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS