Register to reply

Numeric integration in python

by sola maths
Tags: numeric integration, python, scipy
Share this thread:
sola maths
#1
Nov14-12, 02:24 PM
P: 8
I'm trying to write a python program that is able to numerically execute functions of the form:

y(t) = exp(Integrate[A(x),x]) within the bounds of 0 and t

I tried using quad from scipy.integrate but it seems not to be able to evaluate expressions of this form.

Any other suggestions on appropriate packages or commands?
Phys.Org News Partner Science news on Phys.org
Flapping baby birds give clues to origin of flight
Prions can trigger 'stuck' wine fermentations, researchers find
Socially-assistive robots help kids with autism learn by providing personalized prompts
uart
#2
Nov15-12, 06:38 AM
Sci Advisor
P: 2,751
Quote Quote by sola maths View Post
I'm trying to write a python program that is able to numerically execute functions of the form:

y(t) = exp(Integrate[A(x),x]) within the bounds of 0 and t

I tried using quad from scipy.integrate but it seems not to be able to evaluate expressions of this form.

Any other suggestions on appropriate packages or commands?
Can you be a bit more specific sola maths? Do you mean:

[tex]y(t) = \exp(\int_0^t A(x) \, dx)[/tex]

You have some specific function A(x) that you can evaluate numerically?

Also, is that just you integrand? Do you need to evaluate,

[tex]\int_a^b \, e^{\int_0^t A(x) \, dx} \, dt[/tex]
sola maths
#3
Nov15-12, 06:55 AM
P: 8
Hi uart,

Yes, I have some function A(x) that I need to evaluate numerically as x changes. The first expression you wrote is what I meant.

uart
#4
Nov15-12, 07:33 AM
Sci Advisor
P: 2,751
Numeric integration in python

Quote Quote by sola maths View Post
Hi uart,

Yes, I have some function A(x) that I need to evaluate numerically as x changes. The first expression you wrote is what I meant.
Ok so it's just [itex]y(t) = \exp(\int_0^t A(x) \, dx)[/itex] that you need to evaluate.

Quad can do this easily, but only for one particular value of "t" at a time. However you could call it (quad) from within a function if you wished to properly make a function of "t". For example,

def functA(x):
     return x*x/2.0

def functY(t):
     return exp(integrate.quad(functA,0,t)[0])

functY(3)
90.017131300521896
sola maths
#5
Nov15-12, 09:14 AM
P: 8
Your explanation makes lots of sense...

I'd defined a function but had difficulty making it a function of t.... Thanks.


Register to reply

Related Discussions
Compile Python, Matlab and Python Programming & Computer Science 3
Numeric Integration Engineering, Comp Sci, & Technology Homework 0
Many-Body Numeric Integration Algorithm Differential Equations 1
Numeric keypad Computers 0
Numeric Nonsense Fun, Photos & Games 2