Write a function called h mean that takes as input the data set or vector x and
ID: 3758995 • Letter: W
Question
Write a function called h mean that takes as input the data set or vector x and returns the harmonic mean value as the output. Your code should be vectorized using MATLAB’s built-in vector operations, that is there is no need to use loops. An example of correct function behavior is as follows:
>> x = ones(1, 10);
>> m = h_mean(x)
m = 1
>> x = randi([1, 10], 1, 10);
>> m = h_mean(x)
m = 2.9412
I already know that the function is for calculating the harmonic mean of a vector, but I can't seem to assign the variable or output (m) to anything. Or so MATLAB says, CODY as well.
This is what I have so far ...
function m = h_mean(x)
%h_mean calculates the harmonic mean of a term. It takes one parameter as input: the data set or vector (x) and %provides one return value as the output:(m) harmonic mean
n = (1:1:10);
x = (1:1/10:.10);
end
Explanation / Answer
Problem 1 solution is :
>> x = exprnd(1,1,10);
m = harmmean(x);
m
m =
0.2240
Answer for Question 2 is below:
x = exprnd(1,0/10,0.10);
m = harmmean(x);
m
Syntax of exprnd is below: size m and n must be integers not be decimal numbers . so the second exmaple have
the sizes as decimal numbers. so it is giving error
R = exprnd(mu,m,n,...) or R = exprnd(mu,[m,n,...]) generates an m-by-n-by-... array containing random numbers from the exponential distribution with mean parameter mu. mu can be a scalar or an array of the same size as R.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.