Ask Your Question
2

Bug in integration of sqrt functions?

asked 2013-10-09 13:57:17 +0100

Shashank gravatar image

I have been experiencing a problem integrating a function with several terms. I have managed to narrow it down to a problem with integration.

When I type the following command I get 1 as I should

integrate(cos(x),x,0,pi/2)

However, when I write the same integral in the form

integrate((sqrt(1-sin(x)*sin(x))),x,0,pi/2)

I get an error "RuntimeError: ECL says: Error executing code in Maxima: atanh: argument 1 isn't in the domain of atanh."

I guess it is a result of the fact that

integrate((sqrt(1-sin(x)*sin(x))),x,0,pi/2)

gives $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ and sage is trying to substitute $x=\pi/2$ without trying to simplify the expression first or taking the limit of x to $\pi/2$. Is there a way to avoid this problem when the function I wrote is a part of a bigger function and I can't simplify by hand.

Both integrals are identical and I don't understand why I am getting an error in one case. Is this a bug or am I doing something wrong?

edit retag flag offensive close merge delete

Comments

This has been reported upstream - http://www.math.utexas.edu/pipermail/maxima/2013/034222.html - thanks, Dima!

kcrisman gravatar imagekcrisman ( 2013-10-10 10:47:19 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-10-09 22:27:33 +0100

dazedANDconfused gravatar image

I don't think I can answer your questions but maybe we can solve the problem: "Is there a way to avoid this problem when the function I wrote is a part of a bigger function and I can't simplify by hand.". For trig functions there is a simplification command, simplify_trig(), see here, that solves this particular problem but maybe a combination of commands that simplify might be what you need. The command integrate((tan(x)/(sqrt((tan(x)^2+1)))).simplify_trig(),(x,0,pi/2)) will evaluate to 1.

The function (sqrt(1-sin(x)*sin(x)) is really the absolute value of cosine (certainly over 0 to $\pi/2$ they're the same); maybe that's why we get the strange antiderivative. I tried integrate(abs(cos(x)),(x,0,pi)) in a sage notebook and got -1 which is definitely wrong. I couldn't get an answer in the Sage Cell server. The Fundamental Theorem of Calculus expects the antiderivative to be defined on the closed interval $[0,\pi/2]$, but $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ isn't defined when x is a multiple of $\pi/2$. You'll find Sage gives the same error message if you integrate from 0 to $\pi$. In summary, $\tan(x)/\sqrt{(\tan(x)^2 + 1)}$ looks incorrect to me because the domain is not all real numbers but maybe using the simplify commands will let you get your work done.

edit flag offensive delete link more

Comments

I know about simplify_trig() command. However, it is inconvenient when you are multiple calculations in a loop and there are several terms. My point was that you should not have to simplify and then take the limits.

Shashank gravatar imageShashank ( 2013-10-09 22:33:22 +0100 )edit

The above abs(cos(x)) error was already reported at Trac 11483 (currently Trac is down, but you can Google for it). Hopefully Trac 13973 will fix this for good.

kcrisman gravatar imagekcrisman ( 2013-10-10 10:54:55 +0100 )edit

Thanks a lot. It seems it will be fixed in 5.13. Is there a release schedule for this and future versions?

Shashank gravatar imageShashank ( 2013-10-10 19:05:06 +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

Stats

Asked: 2013-10-09 13:57:17 +0100

Seen: 818 times

Last updated: Oct 09 '13