CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    C# ST DEV. Please Help ASAP

    Guys. Im a c# noob but I really need a professional's help. I am using visual studio 2005 for a project so I dont have math.linq I need to calculate the standard deviation of a generic list of objects. The list contains just a list of float numbers, nothing too complicated. However I have never done this before so i need someone to show me that has calculated standard deviation of a generic list before. Here is my code that I tried to start on:

    //this is my list of objects inside. The valve data just contains a bunch of floats.
    public class ValveDataResults
    {
    private List<ValveData> m_ValveResults;

    public void AddValveData(ValveData valve)
    {
    m_ValveResults.Add(valve);
    }
    //this is the function where the standard deviation needs to be calculated:
    public float LatchTimeStdev()
    {
    //below this is a working example of how to get an average or mean
    //of same list and same "LatchTime" that needs to be calculated here as well.
    }
    //function to calculate average of latch time, can be copied for above st dev.
    public float LatchTimeMean()
    {
    float returnValue = 0;
    foreach (ValveData value in m_ValveResults)
    {
    returnValue += value.LatchTime;
    }
    returnValue = (returnValue / m_ValveResults.Count) * 0.02f;
    return returnValue;
    }

    the "Latch Time" is a float object of the "ValveData" object which is inserted into the m_ValveResults list.

    thats it. any help would much be appreciated. Thanks

  2. #2

    Re: C# ST DEV. Please Help ASAP

    All you need is to calculate the standard deviation?

    I feel like I am missing something but here you go

    Code:
            public static float LatchTimeStdev()
            {
                float sum = 0.0f ;
                float mean = LatchTimeMean();
                for (int i = 0; i < m_ValveResults.Count; i++)
                {
                    float val = (mean - m_ValveResults[i].LatchTime);
                     sum += val * val;
                }
                return (float)Math.Sqrt(sum / (m_ValveResults.Count - 1));
            }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured