C # calculates the standard deviation equivalent to the code case for the STDEV function in Excel

Source: Internet
Author: User
Here's a small piece to bring you a C # calculation standard deviation equivalent to the Stdev function instance in Excel. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

Examples are as follows:

public static float StDev (float[] arrdata)//calculate standard deviation    {      float xSum = 0F;      float xavg = 0F;      float ssum = 0F;      float Tmpstdev = 0F;      int arrnum = arrdata.length;      for (int i = 0; i < arrnum; i++)      {        XSum + = arrdata[i]      ;      } Xavg = Xsum/arrnum;      for (int j = 0; J < Arrnum; J + +)      {        ssum + = ((Arrdata[j]-xavg) * (Arrdata[j]-xavg);      }      Tmpstdev = Convert.tosingle (Math.sqrt (Ssum/(arrNum-1)). ToString ());      return tmpstdev;    }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.