Search code examples
pythonnumpyscipyscientific-computing

Triple Integration with Python / Numpy / Scipy


I am new to python and learning by following Python "Scientific lecture notes Release 2013.1" tutorial. Please help me solve this triple intergration problem in the srcreenshot below (Pg 70). I have covered the previous content of that tutorial. Please provide step-wise commands with explanation if possible because being an Aerospace engineer programming concepts are new to me.

Thank You.

http://dl.dropbox.com/u/50511173/Untitled.png

Exercise: Crude integral approximations Write a function f(a, b, c) that returns a^b - c. Form a 24x12x6 array containing its values in parameter ranges [0,1] x [0,1] x [0,1].


Solution

  • It might seem daunting but the question tells you step by step what to do.

    Write a function f(a, b, c) that returns a^b-c.

    def f(a, b, c):
        return a ** b - c
    

    Form a 24x12x6 array containing its parameter ranges [0,1] x [0,1] x [0,1]. Gives you the ogrid hint. So reading the docs I'm guessing that looks like:

    x = np.ogrid[0:1:24j, 0:1:12j, 0:1:6j]
    

    And you can then do

    f(x[0], x[1], x[2])
    

    And take then take the mean

    np.mean(f(x[0], x[1], x[2]))
    

    Which gives me 0.18884234602967925