Hi Angelica! thanks very much for the patch and the work you did. I have couple comments below:
On Tue, Nov 11, 2008 at 12:20 AM, <[EMAIL PROTECTED]> wrote: > > # HG changeset patch > # User Angelica Echavarria-Gregory Add your email address to your ~/.hgrc, e.g. mine looks like this: [ui] username = Ondrej Certik <[EMAIL PROTECTED]> in windows I guess it is some option of TortoiseHg. > # Date 1226355651 18000 > # Node ID 80e7a79d74d398ac99323fd100c56063f2bbedce > # Parent d66dc8f1f1077acc5776284d9fbbcc4c9871fb01 > The function to PLEASE MERGE WITH ALL OF SYMPY FOR IT TO WORK ALONG WITH > OTHER INTEGRALS; > # Please, let's implement this function, we need Sympy to, for example, > recognize when he find this expresion next to a different expression and be > able to solve all together: > > # Thanks Stephan who came up with the idea of converting the poly into a > Gaussian Integral. > > diff -r d66dc8f1f107 -r 80e7a79d74d3 sympy/integrals/integrals.py > --- a/sympy/integrals/integrals.py Fri Oct 24 19:09:04 2008 +0200 > +++ b/sympy/integrals/integrals.py Mon Nov 10 17:20:51 2008 -0500 > @@ -376,4 +376,28 @@ > if isinstance(integral, Integral): > return integral.doit() > else: > - return integral > + return integral > + > + > +# The function to PLEASE MERGE WITH ALL OF SYMPY FOR IT TO WORK ALONG WITH > OTHER INTEGRALS; > +# Please, let's implement this function, we need Sympy to, for example, > recognize when he find this expresion next to a different expression and be > able to solve all together: > + > +# Thanks Stephan who came up with the idea of converting the poly into a > Gaussian Integral. > + > +import sympy > +from sympy import Symbol, integrate, sqrt, simplify, exp, erf, pprint If you use the import statements like this, it won't import: $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sympy Traceback (most recent call last): File "<stdin>", line 1, in <module> File "sympy/__init__.py", line 28, in <module> from integrals import * File "sympy/integrals/__init__.py", line 8, in <module> from integrals import integrate, Integral File "sympy/integrals/integrals.py", line 388, in <module> from sympy import Symbol, integrate, sqrt, simplify, exp, erf, pprint ImportError: cannot import name integrate Also, the convention is to put all import statements on top of the module. > +def GaussIntegral(expr,param,lowerbound,upperbound,z=Symbol('z')): We use Python Style Guidelines: http://www.python.org/dev/peps/pep-0008/ so the function should be namedg auss_integral() and also please use spaces after commans, e.g.: gauss_integral(expr, param, lowerbound, upperbound, z=Symbol('z')) > + """Finds the definite integral of exp(second order polynomial) > expression trough transforming into Gaussian Integral""" Could you please also put some example in the docstring how it is supposed to be used? > + exponent = expr.args[0] > + coeff = exponent.as_poly(param).coeffs > + t1 = sqrt(coeff[0])*param > + t2 = coeff[1]*param/(2*t1) > + square = t1+t2 > + remainder = simplify(exponent-square**2) > + jacobn = 1/square.diff(param) > + result = integrate(exp(-z**2),z).subs(z,square)*jacobn*exp(remainder) > + result The last line (result) is not necessary, right? > + > A=(result.subs(param,upperbound).evalf())-(result.subs(param,lowerbound).evalf()) > + return pprint(A) pprint returns None -- it prints directly to the terminal. I suggest you simply return A, and handle the pprint outside of this function, e.g. the user himself. I am trying to run it, but I am getting some problems -- if you could please give me some examples how you run the function, it be cool. I tried: x = Symbol("x") gauss_integral(exp(x**2), x, -oo, oo) and this is what I get: File "f.py", line 20, in <module> gauss_integral(exp(x**2), x, -oo, oo) File "f.py", line 9, in gauss_integral t2 = coeff[1]*param/(2*t1) IndexError: tuple index out of range See the attached f.py. If you could please modify the f.py to run together with some examples, I'll then help you integrate it well with sympy. Thanks again for your work! Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---
import sympy from sympy import Symbol, integrate, sqrt, simplify, exp, erf, pprint, oo def gauss_integral(expr,param,lowerbound,upperbound,z=Symbol('z')): """Finds the definite integral of exp(second order polynomial) expression trough transforming into Gaussian Integral""" exponent = expr.args[0] coeff = exponent.as_poly(param).coeffs t1 = sqrt(coeff[0])*param t2 = coeff[1]*param/(2*t1) square = t1+t2 remainder = simplify(exponent-square**2) jacobn = 1/square.diff(param) result = integrate(exp(-z**2),z).subs(z,square)*jacobn*exp(remainder) result A=(result.subs(param,upperbound).evalf())-(result.subs(param,lowerbound).evalf()) return pprint(A) x = Symbol("x") gauss_integral(exp(x**2), x, -oo, oo)