Sympy
PostPosted: Thu May 14, 2009 6:40 pm
Alright, so this is a rather in depth question... I know, but this is for those of you who work with the Python Programming Language. My problem is that I'm trying to find a way to pass a function to a method using sympy and mpmath modules. Example
from sympy import *
from mpmath import *
x = Symbol('x')
y = x**2 + x + 10
integral = quad(lambda x: y, [0,10])
print integral
This should print out the integral of x**2 + x + 10 from zero to ten, or anything else y is set to allowing dynamic numerical integral using the Gauss-Legendre method. It would really make my current Thesis problem a lot easier.
Unfortunately, (despite being able to pass everything else in the book). Python is happy with this,
integral = quad(lambda x: x**2 + x + 10, [0,10])
but it doesn't know what to do with this,
integral = quad(lambda x: y, [0,10])
It is as though it is not equating x**2 + x + 10 and y despite my setting them equal. There has to be a way to send a function via this method, otherwise the program is completely worthless (if all it does is take the integral of a pre-defined integral before compile time, then I might as well do the integral by hand). The problem is, I can't find it! Can I maybe get some help from someone else who might know how to fix this? (I'll keep searching too, if I come across the answer, I'll post it here).
Thank you,
Pascal
from sympy import *
from mpmath import *
x = Symbol('x')
y = x**2 + x + 10
integral = quad(lambda x: y, [0,10])
print integral
This should print out the integral of x**2 + x + 10 from zero to ten, or anything else y is set to allowing dynamic numerical integral using the Gauss-Legendre method. It would really make my current Thesis problem a lot easier.
Unfortunately, (despite being able to pass everything else in the book). Python is happy with this,
integral = quad(lambda x: x**2 + x + 10, [0,10])
but it doesn't know what to do with this,
integral = quad(lambda x: y, [0,10])
It is as though it is not equating x**2 + x + 10 and y despite my setting them equal. There has to be a way to send a function via this method, otherwise the program is completely worthless (if all it does is take the integral of a pre-defined integral before compile time, then I might as well do the integral by hand). The problem is, I can't find it! Can I maybe get some help from someone else who might know how to fix this? (I'll keep searching too, if I come across the answer, I'll post it here).
Thank you,
Pascal