473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Normal Distribution

Hi

I need to convert a complicated Excel document that's been created by some Maths boffin into a program in C#. I've been doing really well (despite my Mathematical handicap) until I hit the Excel NORMDIST(x,mean,stdDev,cumulative) function. System.Math doesn't have any functions to help me out here, and I just can't seem to work out how to convert the formula into C# code. I need a function to work the same as the Excel Function with cumulative set to TRUE

Any takers

LittleC
Nov 16 '05 #1
4 24913
LittleC,

If you know that Excel will be installed on the machine that the app
will be on, why not just use interop and call the function yourself?
Surely, the function has a representation in the object model of Excel.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"littlecharva" <an*******@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi,

I need to convert a complicated Excel document that's been created by some Maths boffin into a program in C#. I've been doing really well (despite my
Mathematical handicap) until I hit the Excel
NORMDIST(x,mean,stdDev,cumulative) function. System.Math doesn't have any
functions to help me out here, and I just can't seem to work out how to
convert the formula into C# code. I need a function to work the same as the
Excel Function with cumulative set to TRUE.
Any takers?

LittleC

Nov 16 '05 #2
Hi,

The code is eventually going to be run as an ASP.NET page, so that's out of the question.

LittleC
Nov 16 '05 #3
You can try this. I got the cumulative normal code from
http://www.cs.princeton.edu/introcs/...Math.java.html

using System;
public class blah {
public static double NORMDIST(double x, double mean, double std,
bool cumulative){
if ( cumulative ) {
return Phi( x, mean, std );
} else {
double tmp = 1/((Math.Sqrt(2*Math.PI)*std));
return tmp * Math.Exp(-.5 * Math.Pow((x-mean)/std,2));
}
}
//from http://www.cs.princeton.edu/introcs/...Math.java.html
// fractional error less than 1.2 * 10 ^ -7.
static double erf(double z) {
double t = 1.0 / (1.0 + 0.5 * Math.Abs(z));

// use Horner's method
double ans = 1 - t * Math.Exp( -z*z - 1.26551223 +
t * ( 1.00002368 +
t * ( 0.37409196 +
t * ( 0.09678418 +
t * (-0.18628806 +
t * ( 0.27886807 +
t * (-1.13520398 +
t * ( 1.48851587 +
t * (-0.82215223 +
t * ( 0.17087277))))))))));
if (z >= 0) return ans;
else return -ans;
}

// cumulative normal distribution
static double Phi(double z) {
return 0.5 * (1.0 + erf(z / (Math.Sqrt(2.0))));
}

// cumulative normal distribution with mean mu and std deviation sigma
static double Phi(double z, double mu, double sigma) {
return Phi((z - mu) / sigma);
}
}
littlecharva wrote:
Hi,

I need to convert a complicated Excel document that's been created by some Maths boffin into a program in C#. I've been doing really well (despite my Mathematical handicap) until I hit the Excel NORMDIST(x,mean,stdDev,cumulative) function. System.Math doesn't have any functions to help me out here, and I just can't seem to work out how to convert the formula into C# code. I need a function to work the same as the Excel Function with cumulative set to TRUE.

Any takers?

LittleC

Nov 16 '05 #4
Have you tried NAG? http://www.nag.com/statistical_software.asp

-Naraen
------------
"littlecharva" <an*******@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi,

I need to convert a complicated Excel document that's been created by some Maths boffin into a program in C#. I've been doing really well (despite my
Mathematical handicap) until I hit the Excel
NORMDIST(x,mean,stdDev,cumulative) function. System.Math doesn't have any
functions to help me out here, and I just can't seem to work out how to
convert the formula into C# code. I need a function to work the same as the
Excel Function with cumulative set to TRUE.
Any takers?

LittleC

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christian | last post by:
Hi NG I need to get a normal distribution based on a mean and variance. How do I do that in Java? Is there a standart packet to use? Christian
3
by: Tan Thuan Seah | last post by:
Hi all, I am looking for a way to generate a random number given the variance of a gaussian distribution(or normal distribution). The mean is 0 but the variance will be a user input. Does C++...
5
by: Yudan YI \(OSU\) | last post by:
I want to generate random data from a normal distribution, while I checked the functions, and I found rand(), which returns a pseudorandom integer between zero and RAND_MAX. I am not sure how to...
1
by: atahim | last post by:
I have a query in my database that calculates '# of Days' based on a start and end date and displays it amongst other fields. What i need to do now is develop another query that will give me the...
3
by: PCHOME | last post by:
Hello, Given a mean, standard devaition and the CDF value, I would like to calculate the inverse of a normal distribution. I found this function "double gsl_cdf_gaussian_Pinv (double P, double...
3
by: littlecharva | last post by:
Hi I need to convert a complicated Excel document that's been created by some Maths boffin into a program in C#. I've been doing really well (despite my Mathematical handicap) until I hit the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.