Connecting Tech Pros Worldwide Help | Site Map

Normal Distribution

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 16th, 2005, 12:12 AM
littlecharva
Guest
 
Posts: n/a
Default 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

  #2  
Old November 16th, 2005, 12:12 AM
Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
Default Re: Normal Distribution

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]
- mvp@spam.guard.caspershouse.com

"littlecharva" <anonymous@discussions.microsoft.com> wrote in message
news:4ED2F1DC-421C-4495-ABE9-E6B316FD4194@microsoft.com...[color=blue]
> Hi,
>
> I need to convert a complicated Excel document that's been created by some[/color]
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.[color=blue]
>
> Any takers?
>
> LittleC[/color]


  #3  
Old November 16th, 2005, 12:13 AM
LittleC
Guest
 
Posts: n/a
Default Re: Normal Distribution

Hi,

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

LittleC
  #4  
Old November 16th, 2005, 12:13 AM
Marcus
Guest
 
Posts: n/a
Default Re: Normal Distribution

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:
[color=blue]
> 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[/color]
  #5  
Old November 16th, 2005, 12:24 AM
NaraendiraKumar R. R.
Guest
 
Posts: n/a
Default Re: Normal Distribution

Have you tried NAG? http://www.nag.com/statistical_software.asp

-Naraen
------------
"littlecharva" <anonymous@discussions.microsoft.com> wrote in message
news:4ED2F1DC-421C-4495-ABE9-E6B316FD4194@microsoft.com...[color=blue]
> Hi,
>
> I need to convert a complicated Excel document that's been created by some[/color]
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.
[color=blue]
> Any takers?
>
> LittleC[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.