Advertisement
Guest User

Untitled

a guest
May 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Rem Attribute VBA_ModuleType=VBAModule
  2. Option VBASupport 1
  3.  
  4. Function sort(old_array As Variant) As Variant
  5. Dim n As Integer
  6. n = old_array.Rows.Count
  7. Dim new_array As Variant
  8. new_array = old_array
  9. Dim i As Integer
  10.  
  11. For i = 1 To n
  12. new_array(i, 1) = old_array(i, 1)
  13. Next i
  14.  
  15. Dim j As Integer
  16. Dim l As Integer
  17. Dim m As Double
  18. For i = 1 To n
  19. m = new_array(i, 1)
  20. l = i
  21. For j = i + 1 To n
  22. If new_array(j, 1) < m Then
  23. m = new_array(j, 1)
  24. l = j
  25. End If
  26. Next j
  27. m = new_array(i, 1)
  28. new_array(i, 1) = new_array(l, 1)
  29. new_array(l, 1) = m
  30. Next i
  31. sort = new_array
  32. End Function
  33.  
  34. Function histVar(old_array As Variant, q As Double) As Variant
  35. Dim new_array As Variant
  36. new_array = sort(old_array)
  37. Dim size As Integer
  38. size = old_array.Rows.Count
  39. Dim num As Integer
  40. num = Int(size * (1 - q))
  41. Dim ans As Variant
  42. ReDim ans(1 To 2, 1 To 1)
  43. ans(1, 1) = -new_array(num, 1)
  44. Dim x As Double
  45.  
  46. For i = 1 To num - 1
  47. x = x + new_array(i, 1)
  48. Next i
  49. x = x / (num - 1)
  50. ans(2, 1) = -x
  51. histVar = ans
  52. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement