Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to calculate the mean and the standard deviation of an array of floating-point values in VB.NET

1 Answer

0 votes
Imports System

Class StatsCalculator
    Public Shared Sub Main()
        Dim numbers As Double() = {3.4, 1.8, 4.3, 5.0, 6.2}
		
        Dim mean As Double = CalculateMean(numbers)
        Dim stddev As Double = CalculateStandardDeviation(numbers, mean)
		
        Console.WriteLine($"Mean: {mean}")
        Console.WriteLine($"Standard Deviation: {stddev}")
    End Sub

    Private Shared Function CalculateMean(ByVal data As Double()) As Double
        If data.Length = 0 Then Return 0.0
        Dim sum As Double = 0.0

        For Each value As Double In data
            sum += value
        Next

        Return sum / data.Length
    End Function

    Private Shared Function CalculateStandardDeviation(ByVal data As Double(), ByVal mean As Double) As Double
        If data.Length < 2 Then Return 0.0
        Dim sumOfSquaredDifferences As Double = 0.0

        For Each value As Double In data
            Dim diff As Double = value - mean
            sumOfSquaredDifferences += diff * diff
        Next

        Dim variance As Double = sumOfSquaredDifferences / (data.Length - 1)
		
        Return Math.Sqrt(variance)
    End Function
End Class


  
' run:
' 
' Mean: 4.14
' Standard Deviation: 1.6607227342335025
'

 



answered Jun 29, 2025 by avibootz
...