Question #45551

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.
1

Expert's answer

2014-09-05T11:57:16-0400

Answer on Question #45551 – Engineering - Other

Write a single program that calculates the arithmetic mean (average), rms average, geometric mean and harmonic mean for a set of nn positive numbers. Your program should take two values xx low and xx high and generate 10000 random numbers in the range [xlow...xhigh], and should print out arithmetic mean (average), rms average, geometric mean and harmonic mean.

Code for MatLab:

N=10000;

xl=input('enter xlow ');

xh=input('enter xhigh ');

Numbers=xl+(xh-xl)*rand(N,1);

S=0; % initial arithmetic sum

Rms_Sum=0; % initial rms sum

Geo_Product=1; % initial geometrical sum

Harmonic_Sum=0; % initial harmonic

for i=1:N

S=S+Numbers(i);

Rms_Sum=Rms_Sum+(Numbers(i))^2;

Geo_Product=Geo_Product*Numbers(i);

Harmonic_Sum=Harmonic_Sum+1/(Numbers(i));

end

Arithmetic_Average=S/N

Rms_Average=sqrt(Rms_Sum/N)

Geometric_Mean=(Geo_Product)^(1/N)

Harmonic_Mean=N/Harmonic_Sum

http://www.AssignmentExpert.com/


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!
LATEST TUTORIALS
APPROVED BY CLIENTS