Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

is there a way to integrate without going through an entire list of numbers (Riemann sums and the like) or using symbolic integration while still getting an accurate answer?

Visit calccrypto.wikidot.com for detailed descriptions of algorithms and other crypto related stuff (not much yet, so help would be appreciated).

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

Yes, there are many techniques for numerical integration both with functions and with lists of data points. Can you be a little more specific as to what you are trying to do. Incidentally there are good routines for numerical integration in the sympy package for python.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

im trying to write Cumulative distribution functions, like normalcdf, χ2cdf, tcdf

hello bobbym

*Last edited by calccrypto (2010-04-24 18:04:44)*

Visit calccrypto.wikidot.com for detailed descriptions of algorithms and other crypto related stuff (not much yet, so help would be appreciated).

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi;

Have you taken a look at sympy which is for python. It may already have some of what you need. If not you will have to have to implement a numerical scheme such as simpsons, gaussian or romberg integration.

There are also polynomial approximations that deliver good accuracy and are simpler.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

thanks!

Visit calccrypto.wikidot.com for detailed descriptions of algorithms and other crypto related stuff (not much yet, so help would be appreciated).

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

If you need any help with them just post back.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

im having a little trouble. when doing normalcdf (using simpson's rule), the values are off slightly, but since the real values are small to begin with, the errors are pretty big. i need 2 values 0.219194 and 0.114866, but im getting 0.22649523318724421 and 0.13293551413661003

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi cal;

What are integrating from? From what to what?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

im trying to do ∫ normalpdf(x) (which i believe is e^(-.5x^2)/sqrt(2pi)) dx for:

```
n = 100, z = 1.6 | 1.9
1 - ∑ k from (-n/z+1)/4 to (n/z+1)/4 of [normalcdf(-100,(4k+1)z/sqrt(n)) - normalcdf(-100,(4k-1)z/sqrt(n))] + ∑ k from (-n/z-3)/4 to (n/z-1)/4 of [normalcdf(-100,(4k+3)z/sqrt(n)) - normalcdf(-100,(4k+1)z/sqrt(n))]
```

this is from nist's statistical tests for randomness

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi cal;

Bear with me for a little bit.

Is this what you want?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

no. 1.6/1.9 are the 2 values to use for z in that big mess i have in the code block

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

Since a CDF is an area under the SNC do you know what values you are trying to integrate between?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

from -100 to the z scores, like normalcdf(-100,1.6) (using -100 because -infinity is a little too much), except the formula is a sum of normalcdfs

i dont know if this helps but: http://www.scribd.com/doc/11305936/NIST-Statistical-Test-Suite-for-Random-and-PseudoRandom

page 63; 2.14.8 Example

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

As you can see from above that your cutoff of -100 for - infinty is introducing a small but noticeable error in the CDF

Below is a closed form for the CDF, If you put 1.6 in there you will get the value produced by the second integral 0.945200708300442.

But for the life of me, I cannot determine how he is getting those 2 numbers.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

thanks bobbym!

and the values came from 1-(sum of a bunch of normalcdfs)

edit: oops. i think i referred to the wrong pages. the number on the actual page says 54, but the pdf page says 63. the formula is on the bottom of (pdf) page 62

*Last edited by calccrypto (2010-05-11 10:21:37)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

Where are we now? What do you need? Can you follow that formula because I can hardly see it?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

im just trying to get a more accurate answer, to at least the thousandths place since for p values, they are usually between .01 and .1 ...

you know what? forget this. i have another question: how do you use the GaussKronrod quadrature formula to integrate? what's with those special nodes?

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

Originally, numerical integration using newton - cotes formulas stuck to the idea of sampling the function at equally spaced points. This includes simpsons rule and the

trapezoidal rule as well as Bodes rule... It was Gauss who discovered the way to sample only the best points of a function. To make the best estimate

he had to drop the limitations of equally spaced abscissa. To do that he made use of the so called Legendre polynomials. The nodes are the roots

of those polynomials.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

oh deary me... ive gotten myself into more complicated stuff than ive attempted to learn. oops. i think i'll hold off asking more about this for a few more months, when i finally get into college and have a better background in calc

thanks so much for the help bobbym!

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

Your welcome, sorry I couldn't help you more. Sorry, to jargon you to death, I was just trying to give you a little background. If you feel you would like to wait until you can receive some formal training that is cool. You could also start training yourself. The internet has everything you need to get started and you can always bring your unsolved problems in here. Some one will help you. Do not be discouraged that book was very hard for me as well.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**calccrypto****Member**- Registered: 2010-03-06
- Posts: 96

i try to teach myself here and there and i have learned quite a bit since 2 years ago, but ive had limited experience with polynomials other than using polynomial division to write the AES algorithm in python (a big jump from having a lookup table). i still dont understand so much about polynomials that i would love to know, but are too advanced to learn by skipping around to something interesting that i see

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi calccrypto;

I know the feeling.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,832

Hi carol33;

Welcome to the forum!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

**ShivamS****Member**- Registered: 2011-02-07
- Posts: 3,648

```
from scipy import integrate
def myfunc(x, a, b):
return (x**b) + a
args = (1.0, -2.0)
results = integrate.quad(myfunc, 0.5, 1.5, args)
print 'Integral = ', results[0], ' with error = ', results[1]
```

Offline

Pages: **1**