Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rem Attribute VBA_ModuleType=VBAModule
- Option VBASupport 1
- Function sort(old_array As Variant) As Variant
- Dim n As Integer
- n = old_array.Rows.Count
- Dim new_array As Variant
- new_array = old_array
- Dim i As Integer
- For i = 1 To n
- new_array(i, 1) = old_array(i, 1)
- Next i
- Dim j As Integer
- Dim l As Integer
- Dim m As Double
- For i = 1 To n
- m = new_array(i, 1)
- l = i
- For j = i + 1 To n
- If new_array(j, 1) < m Then
- m = new_array(j, 1)
- l = j
- End If
- Next j
- m = new_array(i, 1)
- new_array(i, 1) = new_array(l, 1)
- new_array(l, 1) = m
- Next i
- sort = new_array
- End Function
- Function histVar(old_array As Variant, q As Double) As Variant
- Dim new_array As Variant
- new_array = sort(old_array)
- Dim size As Integer
- size = old_array.Rows.Count
- Dim num As Integer
- num = Int(size * (1 - q))
- Dim ans As Variant
- ReDim ans(1 To 2, 1 To 1)
- ans(1, 1) = -new_array(num, 1)
- Dim x As Double
- For i = 1 To num - 1
- x = x + new_array(i, 1)
- Next i
- x = x / (num - 1)
- ans(2, 1) = -x
- histVar = ans
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement