zvoulgaris

Weird means drill

Apr 13th, 2021
408
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Statistics
  2.  
  3. const tol = 1e-9 # tolerance threshold
  4. const expo = 1/3 # cube root exponent
  5.  
  6. function agm(x::Real, y::Real)
  7.     while abs(x - y) > tol
  8.         a = (x + y)/2
  9.         b = sqrt(x*y)
  10.         x, y = a, b
  11.     end
  12.  
  13.     return x
  14. end
  15.  
  16. function gmdm(x::Array{<:Real})
  17.     a = mean(x)
  18.     g = (prod(x))^(1/length(x))
  19.     m = median(x)
  20.     x = [a, g, m]
  21.     smallest, largest = extrema(x)
  22.  
  23.     while largest - smallest > tol
  24.         a = mean(x)
  25.         g = (prod(x))^expo
  26.         m = median(x)
  27.         x = [a, g, m]
  28.         smallest, largest = extrema(x)
  29.     end
  30.  
  31.     return a
  32. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×