Ask Your Question

symbolic integration

asked 2017-01-29 05:44:30 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

If you ask sage to symbolically integrate the following properly, the answer is wrong. Why?

cos(x)/(acos(x) + bsin(x))

[Aside -- the captcha was invisible with firefox 50.1/linux, leading to much teeth-gnashing. Seems to work OK with Chrome. Not happy]

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-02-02 01:10:44 +0200

bev gravatar image

The latest linux (slackware) version I was able to find is 7.3, which I'm using. I'll try to find 7.5.1 and report back...

Maple gives a different answer for the integral, and maple has a simplify function which reduces the integral to (bln(acos(x)+b*sin(x))+ax)/(a^2+b^2).

I tried to use the simplify_full function for the sage integral, and it didn't change anything.

In order to get 7.5.1 I downloaded the source code, but it wouldn't compile -- it came up with an error about sem_open, which I traced back to a known error #3770 which I couldn't use to unravel the problem. Accordingly, I tossed the source and downloaded the binary (Ubuntu 64-bit.bz2) and the file terminated abruptly, so I went to MIT -- their download worked, I could unzip and run it. If you've read this far, I have one more request --

When I compare this version of sage to 7.3, this does funny things with colors as I type a line in console mode -- which is especially troubling since it changes open and closed parens to big white blocks. Is there a simple way I can turn that off?

Thanks for your help.

edit flag offensive delete link more


I've edited my answer; as you can see, thanks to some assumptions on the range of x, it's possible to recover Maple's result.

eric_g gravatar imageeric_g ( 2017-02-02 13:42:48 +0200 )edit

answered 2017-01-30 13:36:35 +0200

eric_g gravatar image

updated 2017-02-02 13:40:42 +0200

Can you be more specific? It seems OK to me, since with Sage 7.5.1, we have

sage: var('a b')
(a, b)
sage: f = cos(x)/(a*cos(x) + b*sin(x))
sage: F = integrate(f, x) ; F
2*a*arctan(sin(x)/(cos(x) + 1))/(a^2 + b^2) + b*log(-a - 2*b*sin(x)/(cos(x) + 1) + a*sin(x)^2/(cos(x) + 1)^2)/(a^2 + b^2) - b*log(sin(x)^2/(cos(x) + 1)^2 + 1)/(a^2 + b^2)
sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)

EDIT (2 Feb 2017, after the answer/precisions posted by @bev):

To simplify further Sage's output, we may proceed as follows. First to simplify the arctan part, introduce the double-angle variable u=2*x:

sage: var('u')
sage: F1 = F.subs({x: 2*u}).simplify_full().trig_reduce(); F1
2*a*arctan(tan(u))/(a^2 + b^2) + b*log(-a*cos(2*u)*sec(u)^2 - b*sec(u)^2*sin(2*u))/(a^2 + b^2) - b*log(sec(u)^2)/(a^2 + b^2)

To go further, one has to assume that u in (-pi/2, pi/2), so that arctan(tan(u)) simplifies to u:

sage: assume(u>-pi/2, u<pi/2)
sage: F2 = F1.simplify_full().simplify_log().trig_reduce(); F2
2*a*u/(a^2 + b^2) + b*log(-a*cos(2*u) - b*sin(2*u))/(a^2 + b^2)

Then we can go back to the original variable and get the final result:

sage: F = F2.subs({u: x/2}).simplify_full(); F
(a*x + b*log(-a*cos(x) - b*sin(x)))/(a^2 + b^2)

which coincides with the Maple result that you've quoted, up to some sign in the log argument (which depends on the ranges of a, b and x). The obtained result is indeed correct:

sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)
edit flag offensive delete link more


Thank you for going to this much trouble to share my pain. I was also able to simplify the sage expression, but maple did it all by itself. I don't have maple myself, a [rich] friend did it for me. Thanks again.

bev gravatar imagebev ( 2017-02-03 00:27:29 +0200 )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: 2017-01-29 05:44:30 +0200

Seen: 877 times

Last updated: Feb 02 '17