Ask Your Question

numerial_integral for a function having two variables

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

anonymous user


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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-04-02 15:48:52 +0100

Emmanuel Charpentier gravatar image

updated 2023-04-03 00:27:54 +0100

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.


edit flag offensive delete link 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.

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

Your Answer

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

Add Answer

Question Tools

1 follower


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

Seen: 85 times

Last updated: Apr 03 '23