## #1680 problem with integration

closed
nobody
None
5
2012-12-04
2009-05-28
Anonymous
No

(%i3) integrate((%e**(%i*x))*sin(x),x);
Division by 0
-- an error. To debug this try debugmode(true);
(%i4) integrate((cos(x) + %i*sin(x))*sin(x),x);
sin(2 x)
%i (x - --------) 2
2 cos (x)
(%o4) ----------------- - -------
2 2

Maxima version: 5.18.1
Maxima build date: 11:35 5/25/2009
host type: i686-pc-linux-gnuoldld
lisp-implementation-type: CLISP
lisp-implementation-version: 2.44.1 (2008-02-23) (built 3437275172) (memory 3452232938)

Maybe I don't know something... maybe some mathematic details? Or maybe maxima is using two different methods in each case?

## Discussion

• Dieter Kaiser - 2009-05-28

The problem is the routine sce-int, which uses the following formula:

(%i7) integrate(exp(a*x)*sin(b*x),x);
(%o7) %e^(a*x)*(a*sin(b*x)-b*cos(b*x))/(b^2+a^2)

But for a=%i and b=1 this does not work. b^2+a^2 is zero and we get the error division by zero.

A correct solution after a fix is:

(%i8) integrate(exp(%i*x)*sin(x),x);
(%o8) %i*x/2-%e^(2*%i*x)/4

This is a possible fix:

(defun sce-int (exp s-c var)
(let* ((e-coef (car (islinear (caddr exp) var)))
(sc-coef (car (islinear (cadr s-c) var)))
(abs-val (add (power e-coef 2) (power sc-coef 2))))
(if (zerop1 abs-val)
;; The numerator is zero. Exponentialize the expression
;; and try again.
(\$expand (integrator (\$exponentialize (mul exp s-c)) var))
(mul (div exp (add (power e-coef 2) (power sc-coef 2)))
(if (eq (caar s-c) '%sin)
(mul* (neg sc-coef) `((%cos) ,sc-arg))
(mul* sc-coef `((%sin) ,sc-arg))))))))

Dieter Kaiser

• Dieter Kaiser - 2009-05-28
• milestone: --> Includes_proposed_fix

• Dieter Kaiser - 2009-05-28
• status: open --> closed

• Dieter Kaiser - 2009-05-28

The suggested change has been checked out.

Maxima now gets the result:

(%i14) expand(integrate(exp(%i*x)*sin(x),x));
(%o14) %i*x/2-%e^(2*%i*x)/4

These are the results for related integrands:

(%i15) expand(integrate(exp(x)*sin(%i*x),x));
(%o15) %i*%e^(2*x)/4-%i*x/2
(%i16) expand(integrate(exp(%i*x)*cos(x),x));
(%o16) x/2-%i*%e^(2*%i*x)/4
(%i17) expand(integrate(exp(x)*cos(%i*x),x));
(%o17) %e^(2*x)/4+x/2

Closing this bug report as fixed.

Dieter Kaiser