Answer on Question #45565, Engineering, Other
Question:
write separate functions arithmetic_mean(), rms_average(), harmonic_mean(), geometric_mean() which takes the data array as the argument and compute the respective quantities. Write a script averages which take two values xlow and xhigh and generate 10000 random numbers in the range [xlow...xhigh], and calls the appropriate functions to compute arithmetic mean (average), rms average, geometric mean and harmonic mean.
Answer:
File "arithmetic_mean.m":
function [arithmetic_mean_value] = arithmetic_mean (array)
arithmetic_mean_value = mean(array);
end
File "rms_average.m":
function [rms_average_value] = rms_average (array)
rms_average_value = rms(array);
end
File "harmonic_mean.m":
function [harmonic_mean_value] = harmonic_mean (array)
harmonic_mean_value = geomean(array);
end
File "geometric_mean.m":
function [geometric_mean_value] = geometric_mean (array)
geometric_mean_value = geomean(array);
end
File "averages.m":
function [ ] = averages (xlow, xhigh)
random_array = random('unif', xlow, xhigh, 10000, 1);
average_value = arithmetic_mean(random_array)
rms_value = rms_average(random_array)
geometric_mean_value = geometric_mean(random_array)
harmonic_mean_value = harmonic_mean(random_array)
end
Comments