Ask Your Question
1

Integrate() Error

asked 2020-12-24 15:26:54 -0600

Oscar de Lama gravatar image

For: SageMath version 9.0, Release Date: 2020-01-01 When integrating this:

t = var('t'); f(t) = (sin(2*t)*sin(t))/(cos(t)+3)
a_2 = integrate(f, t, 0, pi)*2/(2*pi)
a_2

Output:

-17

I get -17 ?!

If I just replace sin(2t) with its identity 2sin(t)*cos(t), and integrate again:

t = var('t'); f(t) = (2*sin(t)*cos(t)*sin(t))/(cos(t)+3)
a_2 = integrate(f, t, 0, pi)*2/(2*pi)
a_2

Output:

   -(470832*sqrt(2) - 665857)/(13860*sqrt(2) - 19601)

This last value is the correct one. Simplifying this expression (which I don't know how to do in Sage), you have:

(12*sqrt(2)-17)

It seems like the first result, wrongly reporting -17, somehow is missing the 12*sqrt(2) part of it.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-12-24 18:38:08 -0600

slelievre gravatar image

Sage can call various engines for computing integrals.

The default integration engine Sage calls is Maxima. It gets some integrals wrong, so it's always good to check by computing with several integration engines.

Here is how to tell Sage to ask SymPy, Maxima, Giac, Fricas to compute the integral.

Define the function:

sage: f(t) = (sin(2*t)*sin(t))/(cos(t)+3)
sage: assume(t, 'real')

Integrate (default choice of integration engine):

sage: a_2 = integrate(f(t), t, 0, pi)*2/(2*pi)
sage: a_2
-17

sage: integrate(f, t, 0, pi, algorithm='sympy')
-17*pi + 12*sqrt(2)*pi

sage: integrate(f, t, 0, pi, algorithm='maxima')
-17*pi

sage: integrate(f, t, 0, pi, algorithm='giac')
pi*(12*sqrt(2) - 17)

sage: integrate(f, t, 0, pi, algorithm='fricas')
-17*pi + 12*sqrt(2)*pi

See somewhat longer discussion as part of an answer to a recent question about integration in Sage:

Here is how to get all the results at once as a list:

sage: zz = ['sympy', 'maxima', 'giac', 'fricas']
sage: for z in zz:
....:     print(f"{z}:", integrate(f, t, 0, pi, algorithm=z)/pi)
sympy: -(17*pi - 12*sqrt(2)*pi)/pi
maxima: -17
giac: 12*sqrt(2) - 17
fricas: -(17*pi - 12*sqrt(2)*pi)/pi

(Only include FriCAS if it is installed, otherwise an error will be raised instead of displaying the last result.)

To get the results in a list:

sage: zz = ['sympy', 'maxima', 'giac', 'fricas']
sage: aa = [integrate(f, t, 0, pi, algorithm=z) for z in zz]
sage: aa
[-17*pi + 12*sqrt(2)*pi,
 -17*pi,
 pi*(12*sqrt(2) - 17),
 -17*pi + 12*sqrt(2)*pi]

Example on SageCell:

edit flag offensive delete link more

Comments

Great! Thanks a lot!

Oscar de Lama gravatar imageOscar de Lama ( 2021-01-02 21:13:48 -0600 )edit

Glad I could help!

Consider accepting the answer.

This is done by clicking the "accept" button, the button consisting of a tick mark "✓" icon, located to the left of the top of the answer, below the "upvote" and "downvote" buttons and the answer's score.

This marks the question as solved in the list of questions.

This saves time for people looking for unsolved questions to answer.

slelievre gravatar imageslelievre ( 2021-01-03 08:38:31 -0600 )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

Stats

Asked: 2020-12-24 15:26:54 -0600

Seen: 45 times

Last updated: Dec 24 '20