We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Bell Curve

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

4
Contributors
4
Replies
20 Hours
Discussion Span
2 Years Ago
Last Updated
6
Views
Question
Answered
Mikey12345
Light Poster
30 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
Skill Endorsements: 2

@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.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3

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

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
Skill Endorsements: 2

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;
        }
    }
}
ddanbe
Industrious Poster
4,307 posts since Oct 2008
Reputation Points: 2,126
Solved Threads: 725
Skill Endorsements: 26
Question Answered as of 2 Years Ago by Lusiphur, ddanbe and nick.crane

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0641 seconds using 2.67MB