Ask Your Question

Wrong answer for complex integral with maxima

asked 2024-03-25 19:18:19 +0200

Nate Eldredge gravatar image

I was trying to do the contour integral $\int_C |z-1|^2 dz$ along the upper unit semicircle, and tried

t = var('t')
integrate(abs(exp(i*t)-1)^2*i*exp(i*t), (t,0,pi))

The answer returned was $-\frac{8}{3}$, which is wrong. The correct answer is $-4-i\pi$, which is given by the giac and sympy solvers.

It seems that maybe it is ignoring the absolute value, as we do have $\int_C (z-1)^2 dz = -\frac{8}{3}$.

Is this a bug in Maxima and/or Sage, or am I doing something silly?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2024-03-27 19:08:37 +0200

dan_fulea gravatar image

Yes, the absolute value is omitted, as seen from integrating without limits, then differentiating the result:

sage: assume(t, 'real')
sage: integrate(abs( (exp(i*t) - 1)^2 ) * i * exp(i*t), t).diff().factor()
I*(e^(I*t) - 1)^2*e^(I*t)

The problem is that the machine was not really educated to take the absolute value correctly, here it must isolate the real and imaginary parts, compute the absolute value, then integrate this value. In giac we have the right answer:

sage: integrate(abs(exp(i*t) - 1)^2 * i * exp(i*t), (t, 0, pi), algorithm='giac')
-I*pi - 4

The expectation that the computer does and must do always the right thing is not really realistic. If it is a must, then the implementers must be written on a black list and punished. However, the implementers are on my list at the top, they did the best, and combined with human common sense and checks the work is almost always done.

In our case, let us explicitly help the integrator:

sage: integrate( (real(exp(i*t) - 1)^2 + imag(exp(i*t) - 1)^2) * i * exp(i*t), t, 0, pi)
-I*pi - 4

sage: integrate(abs((cos(t) + i*sin(t) - 1)^2) * i * exp(i*t), (t, 0, pi))
-I*pi - 4
edit flag offensive delete link more

answered 2024-04-01 12:14:54 +0200

Emmanuel Charpentier gravatar image


sage: var("t")
sage: integrate(abs(exp(i*t).demoivre()-1)^2*i*exp(i*t), (t,0,pi))
-I*pi - 4


edit flag offensive delete link more

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: 2024-03-25 19:18:19 +0200

Seen: 125 times

Last updated: Apr 01