I am trying to numerically integrate a function with respect to one variable, although the function is of more than one variable. An example:
var('x')
var('a')
f(x,a)=a*x
f(x,a)
integral(f(x,a),x,0,1)
produces the correct result of 1/2*a
g(x,a)=(f(x,a).nintegral(x, 0, 1))
Errors with "ValueError: Maxima (via quadpack) cannot compute the integral", but I probably don't have the syntax correct even if that function can do this. Even if a is given a value prior to the g(x,a) definition, it doesn't work.
g(x,a)=numerical_integral(f(x,a),0,1)
Errors with "ValueError: Integrand has wrong number of parameters". I can understand this, as it doesn't quite know what to do with 'a'.
g(x,a)=numerical_integral(f(x,a),0,1, params=[a])
g(x,6)
Gives an incorrect result of 0.3333
g(x,a)=numerical_integral(f(x,a),0,1, params=[6])
g(x,a)
Gives the correct result of 2.99996
h(x,a)=integral(f(x,a),x,0,1)
h(x,6)
Gives the correct result of 3
What is going on with g(x,a) and the "params" vector? Is what I am attempting to do possible?
I would like to make a plot of g(x,a) across a range of a. This is a simplified example, where I could obviously just do it by hand or with a non-numerical integral. The f(x,a) that I am really trying to work with is much more complex. I can upload a .sws workbook with these equations if that helps.
The documentation at http://www.sagemath.org/doc/reference/calculus/sage/gsl/integration.html don't give much to go on with respect to params or nintegral. Any other docs out there I am missing?