1,105,169 Community Members

Bell Curve

Member Avatar
Mikey12345
Light Poster
30 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

Is there a frequency function in C# like there is in Excel. I need to show a distribution chart in bell curve form.


Thanks

Member Avatar
Lusiphur
Practically a Posting Shark
852 posts since Jun 2010
Reputation Points: 185 [?]
Q&As Helped to Solve: 134 [?]
Skill Endorsements: 4 [?]
Team Colleague
Featured
 
0
 

This library entry at msdn.microsoft.com might get you closer to what you're looking for if you're looking for a graphical output based on your data. At the least it should get you closer to what you need even if you need to modify the sample method they provide to fit your needs.

Hope this helps :) Please mark as solved if it resolves your issue.

Member Avatar
nick.crane
Veteran Poster
1,195 posts since Feb 2010
Reputation Points: 342 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 5 [?]
 
0
 

@Lusiphur: The LinearGradientBrush is used to fill a shape using linear shading. It does not draw a curved line. This will not help.
I don't think there is anything native to .Net that supports drawing bell curves.
May be someone else can help.

Member Avatar
Lusiphur
Practically a Posting Shark
852 posts since Jun 2010
Reputation Points: 185 [?]
Q&As Helped to Solve: 134 [?]
Skill Endorsements: 4 [?]
Team Colleague
Featured
 
0
 

I was tossing the only thing I could find in there since I, also, don't know of anything in .Net that does "exactly" what they're looking for. You can't expect all of my posts to be gold can you? :P

Member Avatar
ddanbe
Posting Expert
5,336 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
1
 

It is really hot overhere(34°C) but I still managed to do a bit of programming. Having no swimming pool around, what else can a man do? ;)
So here it is, hope it helps.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] D = { 5, 2, 7, 8, 11, 12, 3, 1, 2, 10 };
            double[] B = { 4, 8 };
            double[] F = FREQUENCY(D, B);
            for (int i = 0; i < F.Length; i++)
            {
                Console.WriteLine(F[i]);
            }           
            Console.WriteLine(NORMDIST(1,42,1.5,false));
            Console.ReadKey();
        }

        // QAD, so little error checking
        public static double[] FREQUENCY(double[] Data, double[] Bins)
        {
            double[] FreqList = new double[Bins.Length + 1];
            for (int i = 0; i < FreqList.Length; i++)
            {
                FreqList[i] = 0.0; //init our list
            }
            for (int i = 0; i < Data.Length; i++)
            {
                for (int j = 0; j < Bins.Length; j++)
                {
                    if (Data[i] <= Bins[j])
                    {
                        FreqList[j]++;
                        break; // we don't want to fill others
                    }
                }
                if (Data[i] > Bins[Bins.Length - 1])
                {
                    FreqList[Bins.Length]++;
                }
            }
            return FreqList;
        }

        //evaluation of the bell curve. See http://en.wikipedia.org/wiki/Normal_distribution
        public static double NORMDIST(double x, double mean, double standard_dev, bool cumulative)
        {
            double fact = standard_dev * Math.Sqrt(2.0 * Math.PI);
            double expo = (x - mean) * (x - mean) / (2.0 * standard_dev * standard_dev);
            //if (cumulative) do integration from 0 to x
            //look at this snippet for A way not THE way to do this:
            //http://www.daniweb.com/code/snippet217197.html
            //else just return the value:
            return Math.Exp(-expo) / fact;
        }
    }
}
Question Answered as of 3 Years Ago by Lusiphur, ddanbe and nick.crane
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: