3

I want to choose which variable will be the integration variable in a function when I integrate it with scipy.integral.quadrature. for example

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

print scipy.integrate.quadrature(f,0,3,args=(2,3))

This code works nice and the result is 17.9999999999 as it should be. What should I write in quadrature parenthesis if I wanted b to be my integration variable and not x? Also in args can I set the values by name, for example a=2 b=3? I want to apply quadrature in functions with more arguments and I don't want the user to remember the queue of arguments, just setting the integration variable and giving values to the others, which are parameters, just by name.

Ippolitos
  • 41
  • 4

1 Answers1

1

The first variable is the one being integrated, so to integrate on b define the function as f(b,a,x) for example.

args passes a tuple so it will have to be ordered. If you don't want the user to have to use order, then just wrap the function in another function that wraps the integrate.quadrature part and gets a and b as parameters (unordered), and then you can just use args(a,b) and your problem is solved.

Bitwise
  • 7,577
  • 6
  • 33
  • 50