# numerial_integral for a function having two variables

Anonymous

Why the following code does not work with SageMath version9, though it works with SageMath version8?

f(x,y)=sin(x+2*y) numerical_integral(f,0,pi,params=[5])

SageMath version8.6 gives (-1.6781430581529053, 2.2206773047754592e-14). SageMath version9.7 gives (0.0, 0.0).

Execution of numerical_integral(f(x,5), 0, pi) in SageMath version9.7 also gives (-1.6781430581529053, 2.2206773047754592e-14).

edit retag close merge delete

Sort by ยป oldest newest most voted

Your params=[5] seems to indicate that you want the second parameter of fto be 5, but this is highly ambiguous, and depending of the original definition of f : what if f was defined with a default ? What if y was a keyword parameter ?

An unambiguous way to get the same result is :

sage: numerical_integral(lambda u:f(u,5), 0, pi)
(-1.6781430581529053, 2.2206773047754592e-14)


The anonymous function has exactly one parameter, and so does numerical_integral of this function.

HTH,

more

There is really a bug in numerical_approximation. Try this example included in the docs:

sage: f(x,a) = 1/(a+x^2)
sage: [numerical_integral(f, 1, 2, max_points=100, params=[n]) for n in range(10)]


According to the docs, the output should be

[(0.49999999999998657, 5.5511151231256336e-15),
.....................
(0.088750683050217577, 9.8533051773561173e-16)]


However one gets a big amount of blank space and

[(0.0, 0.0),
(0.0, 0.0),
..............
(0.0, 0.0)]


It can be seen in this SageMath cell.

( 2023-04-06 04:13:57 +0100 )edit

Please start posting anonymously - your entry will be published after you log in or create a new account.

## Stats

Asked: 2023-03-19 15:52:31 +0100

Seen: 85 times

Last updated: Apr 03 '23