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

You are not logged in.

## #1 2010-04-25 11:14:22

calccrypto
Full Member

Offline

### how to integrate using python

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).

## #2 2010-04-25 11:33:24

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #3 2010-04-25 13:42:24

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

hello bobbym

Last edited by calccrypto (2010-04-25 16:04:44)

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

## #4 2010-04-25 16:13:51

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #5 2010-04-26 04:12:37

calccrypto
Full Member

Offline

### Re: how to integrate using python

thanks!

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

## #6 2010-04-26 04:42:00

bobbym

Offline

### Re: how to integrate using python

If you need any help with them just post back.

In mathematics, you don't understand things. You just get used to them.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #7 2010-05-09 11:54:52

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

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

## #8 2010-05-09 15:31:29

bobbym

Offline

### Re: how to integrate using python

Hi cal;

What are integrating from? From what to what?

In mathematics, you don't understand things. You just get used to them.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #9 2010-05-11 08:30:24

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

#### Code:

```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

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

## #10 2010-05-11 12:42:26

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #11 2010-05-11 20:21:16

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

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

## #12 2010-05-11 20:24:33

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #13 2010-05-12 06:13:49

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

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

## #14 2010-05-12 06:35:07

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #15 2010-05-12 08:09:25

calccrypto
Full Member

Offline

### Re: how to integrate using python

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-12 08:21:37)

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

## #16 2010-05-12 11:45:18

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #17 2010-05-12 12:16:02

calccrypto
Full Member

Offline

### Re: how to integrate using python

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 Gauss–Kronrod quadrature formula to integrate? what's with those special nodes?

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

## #18 2010-05-12 13:29:56

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #19 2010-05-12 13:47:40

calccrypto
Full Member

Offline

### Re: how to integrate using python

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!

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

## #20 2010-05-12 13:56:55

bobbym

Offline

### Re: how to integrate using python

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.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #21 2010-05-12 20:19:58

calccrypto
Full Member

Offline

### Re: how to integrate using python

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

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

## #22 2010-05-12 20:47:14

bobbym

Offline

### Re: how to integrate using python

Hi calccrypto;

I know the feeling.

In mathematics, you don't understand things. You just get used to them.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #23 2011-08-15 17:47:49

carol33
Novice

Offline

### Re: how to integrate using python

Thanks for letting me know about other good stuff !

## #24 2011-08-15 21:05:26

bobbym

Offline

### Re: how to integrate using python

Hi carol33;

Welcome to the forum!

In mathematics, you don't understand things. You just get used to them.
Probability is the most important concept in modern science, especially as nobody has the slightest notion what it means.
90% of mathematicians do not understand 90% of currently published mathematics.

## #25 2011-09-03 10:32:50

Shivamcoder3013
Super Member

Offline

### Re: how to integrate using python

#### Code:

```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]```

Give me a lever long enough and a fulcrum on which to place it, and I shall move the world.
-Archimedes
My maturity level depends on the people I am around.