Matlab:
Need to make a function that displays indices of negative values of a set of numbers and calculates the harmonic mean.
b) The harmonic mean is another way of calculating a mean for a set of natural numbers, which is given by the equation:
harmonic mean = √(n / (∑(1 / x)^2))
Write a function named [ind, hm] = myHarmmean(x) that accepts a vector x of arbitrary length n: x = [x1, x2, ..., xn], and returns the indices of non-positive elements of x in ind and the harmonic mean of positive elements of x.
For example:
x = [1, -1, 2.3, 4, -3, 6.5];
[ind, hm] = myHarmmean(x);
ind = [2, 5]
hm = 2.1755
Verify your function on two examples of your choice (with different lengths n > 5 and the vector must include negative elements), and print your results and the results returned by the built-in MATLAB function harmmean. Note: you are not allowed to call the built-in MATLAB function harmmean in myHarmmean.