Click here to Skip to main content
15,892,161 members
Articles / Programming Languages / C# 4.0

Process Performance Determination in C# Part 4

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
29 Jun 2012CPOL4 min read 16.3K   144   2  
The program presented here provides a simple way to obtain process performance through Z-transformation.
  • ProcessPerformance4.zip
    • ProcessPerformance4
      • ExcelNORMSDIST
      • Local.testsettings
      • ProcessPerformance4.sln
      • ProcessPerformance4.suo
      • ProcessPerformance4.vsmdi
      • ProcessPerformance4
      • TestProcessPerformance4
      • TestResults
        • Sitt_JANAKA-PC 2012-06-21 15_25_25.trx
        • Sitt_JANAKA-PC 2012-06-21 15_37_11.trx
        • Sitt_JANAKA-PC 2012-06-21 15_37_40.trx
        • Sitt_JANAKA-PC 2012-06-21 15_55_12.trx
        • Sitt_JANAKA-PC 2012-06-21 15_55_12
          • In
            • JANAKA-PC
          • Out
            • AgentRestart.dat
        • Sitt_JANAKA-PC 2012-06-21 15_57_59.trx
        • Sitt_JANAKA-PC 2012-06-21 15_57_59
          • In
            • JANAKA-PC
          • Out
            • AgentRestart.dat
        • Sitt_JANAKA-PC 2012-06-21 16_01_07.trx
        • Sitt_JANAKA-PC 2012-06-21 16_07_56.trx
        • Sitt_JANAKA-PC 2012-06-21 17_13_54.trx
        • Sitt_JANAKA-PC 2012-06-21 17_14_22.trx
        • Sitt_JANAKA-PC 2012-06-26 15_56_21.trx
      • TraceAndTestImpact.testsettings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExcelNORMSDIST
{
    public class Excel
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Value for NORMSDIST(0) is: {0}.", NORMSDIST(0));
            Console.WriteLine("Value for NORMSDIST(0.2) is: {0}.", NORMSDIST(0.2));
            Console.WriteLine("Value for NORMSDIST(-0.2) is: {0}.", NORMSDIST(-0.2));
            Console.WriteLine("Value for NORMSDIST(-1) is: {0}.", NORMSDIST(-1));
            Console.WriteLine("Value for NORMSDIST(-2) is: {0}.", NORMSDIST(-2));
            Console.WriteLine("Value for NORMSDIST(-3) is: {0}.", NORMSDIST(-3));
            Console.WriteLine("Value for NORMSDIST(-4) is: {0}.", NORMSDIST(-4));
            Console.WriteLine("Value for NORMSDIST(-5) is: {0}.", NORMSDIST(-5));
            Console.WriteLine("Value for NORMSDIST(-7) is: {0}.", NORMSDIST(-7));
            Console.ReadKey();
        }

        public static double NORMSDIST(double z)
        {
            double sign = 1;
            if (z < 0) sign = -1;
            return 0.5 * (1.0 + sign * erf(Math.Abs(z) / Math.Sqrt(2)));
        }

        private static double erf(double x)
        {
            //A&S formula 7.1.26
            double a1 = 0.254829592;
            double a2 = -0.284496736;
            double a3 = 1.421413741;
            double a4 = -1.453152027;
            double a5 = 1.061405429;
            double p = 0.3275911;
            x = Math.Abs(x);
            double t = 1 / (1 + p * x);
            //Direct calculation using formula 7.1.26 is absolutely correct
            //But calculation of nth order polynomial takes O(n^2) operations
            //return 1 - (a1 * t + a2 * t * t + a3 * t * t * t + a4 * t * t * t * t + a5 * t * t * t * t * t) * Math.Exp(-1 * x * x);

            //Horner's method, takes O(n) operations for nth order polynomial
            return 1 - ((((((a5 * t + a4) * t) + a3) * t + a2) * t) + a1) * t * Math.Exp(-1 * x * x);
        }
    }//end class program
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Foundasoft.com
Malaysia Malaysia
Consultant

Comments and Discussions