Use visual basic to perform the following tasks Create a pro
Use visual basic to perform the following tasks: Create a procedure which does the following: Clears the content of the current worksheet. Randomly generate 10 numbers between 1 and 10. Finds the mean and standard deviation of the numbers generated and stores them as variables. Create a procedure which does the following: Generates 10 random numbers from the Normal distribution using the mean and standard deviation found in part (a). Use the Application object and the Rnd() VBA function to generate the random numbers. Graph the data generated in part (a) and the Normal random variables using a Line chart. Create a procedure which does the following: Generates 10 random numbers from the Exponential distribution using the mean found in part (a). Use the Application object and the Log() and Rnd() functions to generate the random numbers. Graph the data generated in part (a) and the Exponential random variables using a Line chart.
Solution
25)
a. (i) CODE:
a (ii) CODE:
a (iii) CODE:
Function Mean(k As Long, Arr() As Single)
Dim Sum As Single
Dim i As Integer
Sum = 0
For i = 1 To k
Sum = Sum + Arr(i)
Next i
Mean = Sum / k
End Function
STANDARD DEVIATION:
Function StdDev(k As Long, Arr() As Single)
Dim i As Integer
Dim avg As Single, SumSq As Single
avg = Mean(k, Arr)
For i = 1 To k
SumSq = SumSq + (Arr(i) - avg) ^ 2
Next i
StdDev = Sqr(SumSq / (k - 1))
End Function
