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 positive numbers. Your program should take two values low and 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/
Comments