473,465 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 24930
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.