473,320 Members | 1,953 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,320 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 24890
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.