jmbejara / comp-econ-sp18

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2018)
16 stars 23 forks source link

integration with scipy- normal distribution #5

Closed alykhanb96 closed 6 years ago

alykhanb96 commented 6 years ago

I'm stuck on this integration. I think I'm not using scipy correctly. Any one have any suggestions on a better approach

`result = scipy.integrate.quad(lambda x: (1.0/(23.14154)1/2)np.exp(-1((x-1)2)/2*4)), -2, 2)

SyntaxError: invalid syntax`

alykhanb96 commented 6 years ago

revision- but i still have a problem the actual code result = scipy.integrate.quad(lambda x: ((1.0/(2*3.1415*4)**1/2)*np.exp(-1*((x-1)**2)/2*4)), -2, 2) print(result) gets me the result

(0.024367361811287402, 4.612853002624809e-13)

but this is not the right answer i think

Jacob-Bishop commented 6 years ago

So I think your error is that you're multiplying 1*((x-1)*2)/2 times 4 instead of dividing -1((x-1)*2) by (24). Also, as a side note I noticed both numpy and math modules have built-in approximations for pi, you don't have to approximate it yourself.

jmbejara commented 6 years ago

Ditto on Jacob's comments. Also watch out for order of operations on the exponentiation: 2**1/2 is not the same as 2**(1/2). Let me know if this helps!

Also, Jacob is referring to these:

import math
import numpy as np

math.pi
np.pi