Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The geometric mean ( Qn i = 1 ai ) 1 / n may cause numerical instability if the products become too large. One simple
The geometric mean
Qn
i ai
n may cause numerical instability if the products become too large. One
simple way of overcoming this issue is to use the identity
Yn
i
ai
n
exp
n
Xn
i
log ai
The code chunk below implements the identity above as the function gmean:
gmean functionx expmeanlogx
Mike would like to compute the geometric mean for each of columns of a numeric matrix y He did it
using a for loop, see the code he used in the chunk below.
ygmean numeric
fori in :
ygmeani gmeanyi
Sally saw Mikes code and said he could have achieved the same result using vectorisation ie without using
for or while which is more efficient computationally. Write down a piece of code that would achieve the
same result as Mikes code above, but using vectorisation instead of a for loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started