# Thread: Calculus: Integration possible with Javascript?

1. ## Calculus: Integration possible with Javascript?

I'm writing a script for a mathematics statistics class that will show students how the normal distribution works (using z tables). In order to get the script to work I either need to code the z tables manually (big pain) or find some javascript tool that will integrate a function (by integration, I mean the integration one does in calculus).

Does anyone know if Javascript can do integration? If so could you point me in the right direction.

Thanks!
Stephanie

2. Take a look at

http://math2.org/math/stat/distributions/z-dist.htm

They are doing some kind of calculations on that page

3. Thanks...this was just what I needed. The code on that page was a little wonky so I refactored it a bit and here's what I came up with:

Code:
```function GetZPercent(z)
{
//z == number of standard deviations from the mean

//if z is greater than 6.5 standard deviations from the mean
//the number of significant digits will be outside of a reasonable
//range
if ( z < -6.5)
return 0;
if( z > 6.5)
return 1;

var factK = 1;
var sum = 0;
var term = 1;
var k = 0;
var loopStop = Math.exp(-23);
while(Math.abs(term) > loopStop)
{
term = .3989422804 * Math.pow(-1,k) * Math.pow(z,k) / (2 * k + 1) / Math.pow(2,k) * Math.pow(z,k+1) / factK;
sum += term;
k++;
factK *= k;

}
sum += 0.5;

return sum * 100;
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•