1

I'm learning about using simpson's method for integration. I've been reading material to learn the basis of using it but I am still having trouble even getting it to work

import numpy as np
import scipy.integrate as integrate

x = np.array[0.1,50] 
y = 0.04*(x**(0.2*x))
result = integrate.simps(y,x)
print result

My problems with the above code are:

1) The first issue has been solved and edited

2) I don't fully understand how the integrate command should work. I know that in integrate.simps(y,x) y represents my function/polynomial to be integrated and x represents the points at which y is evaluated.

3) I do not understand how or where to adjust the number of intervals (N) for my integral

4) my x = np.array[] produces an error message 'builtin_function_or_method' object has no attribute 'getitem'

The function i'm trying to integrate is:

∫x*(0.4x^(.2x))

upper limit : 50.0

lower limit : 0.1

  • to answer the first, you want to use `import scipy.integrate as integrate` or `from scipy import integrate` to import the module instead of importing the `simps` directly. – Tadhg McDonald-Jensen Mar 31 '16 at 01:10
  • Ok, thanks @Tadhg McDonald-Jensen , I understand that change. After making your recommended change, my code now produces an error involving the x = np.array[0.1,50] 'builtin_function_or_method' object has no attribute '__getitem__' – HopefulPhysicsMajor Mar 31 '16 at 01:14

1 Answers1

0

For your second problem, use parentheses for the array()

x = np.array( [0.1,50]  )