0

I want to use a function as variable of integration for example in evaluating the integral over:

e^(cos(x))f(sin(x))dcos(x)

in which f(x) is an arbitrary function.

How can I change the variable of integration such that I integrate over dcos(x), instead of dx (as is default)?

EDIT:

When evaluating an integral such as a*x+b, one can evaluate it in the following way:

  def f(x,a,b):
    return a*x+b

  print quadrature(f,0,1,args=(2,3))

In this example the variable of integration is dx, but now I want to change the variable of integration to a function, such as x**2 (I know this can be solved analytically, but I want to apply it so a function that is not analytically solvable.), or cos(x).

5
  • Please check stackoverflow.com/help/mcve and post some specific details about the issue... Commented Oct 30, 2014 at 15:11
  • I just don't understand a single word of your question. Not everyone here has a maths degree you know, some of us are just programmers... Commented Oct 30, 2014 at 15:12
  • Sorry, I've changed it into a more understandable language. But I think that the question will be answered by someone who at least understands the first part, as it is first year university calculus. Commented Oct 30, 2014 at 15:20
  • This question appears to be off-topic because it is about a purely mathematical concept. An appropriate solution could be found on mathematics.stackexchange.com Commented Oct 30, 2014 at 15:22
  • 1
    It is not a mathematical question, purely on how to implement this issue, using Scipy or Numpy. Commented Oct 30, 2014 at 15:23

1 Answer 1

1

You seem to be asking how to make numpy/scipy change integration variables for you. This in general requires symbolic computation (in your example: you need to use the relation between sine and cosine), and scipy does not have that.

Your best bet is to work out the transformation of variables by paper-and-pencil, write down the resulting integral, and use scipy to evaluate that.

If you look for symbolic computation tools in python land, have a look at sympy.

EDIT: of course, you could always sample your functions on a mesh of x, use interpolation to construct an implicit function, and integrate that [in your example: sample f(x) and cos(x) on a mesh of x, interpolate f vs x and x vs cos(x)]. Maybe your specific problem is such that it's actually worth it, so YMMV.

Sign up to request clarification or add additional context in comments.

4 Comments

I am not looking for a symbolic computation, because it doesn't exist for this particular problem, so working it out by hand also won't be possible.
this does not change the answer to the question of whether scipy can change integration variables for you: it can't.
It might not be directly possible, but this problem must be numerically solvable, it's been done in literature many times, but unfortunately they never specify their methods.
See my edited answer. It seems to me you'd hardly get any more specific answer given the level of detail and amount of effort in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.