Can Python handle numeric integration with exponential functions?

In summary, the conversation revolves around writing a python program to numerically execute functions of the form y(t) = exp(Integrate[A(x),x]) within the bounds of 0 and t. The speaker had tried using quad from scipy.integrate but it was not able to evaluate expressions of this form. They are seeking suggestions for other packages or commands that could handle this type of expression. The conversation also touches on the specifics of the function A(x) and the need to evaluate it numerically as x changes. The speaker is ultimately advised to use quad within a function to properly make it a function of t.
  • #1
sola maths
8
0
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?
 
Technology news on Phys.org
  • #2
sola maths said:
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]
 
  • #3
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.
 
  • #4
sola maths said:
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,

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

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

functY(3)
90.017131300521896
 
  • #5
Your explanation makes lots of sense...

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

FAQ: Can Python handle numeric integration with exponential functions?

What is numeric integration in python?

Numeric integration in python is a method used to approximate the area under a curve or the integral of a function. It involves dividing the area into smaller, simpler shapes and summing their areas to get an approximate value.

What is the difference between numerical integration and analytical integration?

Numerical integration, also known as numerical quadrature, uses numerical methods to approximate the integral of a function. Analytical integration, on the other hand, solves integrals using algebraic methods and provides an exact solution.

What are the advantages of using python for numeric integration?

Python is a powerful and versatile programming language that is widely used in scientific computing. It has libraries such as NumPy and SciPy that provide efficient and accurate numerical integration methods. Additionally, python's simple syntax and readability make it easy to implement and debug numerical integration algorithms.

What are some common numerical integration methods used in python?

Some common numerical integration methods used in python include the trapezoidal rule, Simpson's rule, and Gaussian quadrature. These methods vary in accuracy and computational complexity, allowing for flexibility in choosing the appropriate method for a specific problem.

How can I check the accuracy of my numerical integration results in python?

One way to check the accuracy of numerical integration results in python is by comparing them to the exact solution, if available. Another way is to use convergence tests, such as Richardson extrapolation, to estimate the error and improve the accuracy of the results.

Similar threads

Replies
1
Views
919
Replies
4
Views
5K
Replies
16
Views
1K
Replies
9
Views
9K
Replies
6
Views
6K
Replies
3
Views
1K
Replies
3
Views
3K
Replies
6
Views
3K
Replies
7
Views
4K
Back
Top