3

I'm trying to obtain a numerical solution to the following integral:

numerical integral 1

The correct answer is -0.324 + 0.382i but as seen below I am not getting a numerical answer and would appreciate help with the Maxima syntax. Maxima input and output 2

Perhaps related to why I am not getting a numerical output are two specific questions:

  1. I read that e and i in Maxima need to be preceded by % in input but should these also appear as %e and %i as seen in the Maxima output?
  2. Why is dy missing at the end of the integral in the Maxima output?

Thank you!

Carey
  • 67
  • 5

1 Answers1

3

Looks to me like your input is okay, however, the function to compute approximations to integrals is named quad_qags. (There are actually several related functions. See ?? quad_ for more info.) Also, a wrinkle here is that the integrand is a complex-valued function (of a real variable), and quad_qags can only work on real-valued integrands, so we'll have to work around it. Here's how I would arrange it.

myintegrand: exp(%i*(1 + %i*y))/(1 + %i*y + 1/(1 + %i*y));
result_realpart: quad_qags (realpart (myintegrand), y, 0, 6);
result_imagpart: quad_qags (imagpart (myintegrand), y, 0, 6);
result: result_realpart[1] + %i*result_imagpart[1];

I get 0.3243496676292901*%i + 0.3820529930785175 as the final result. That's a little different from what you said; maybe a minus sign went missing? or there's a missing or extra factor of %i?

A quick approximation

0.1 * lsum (x, x, float (rectform (makelist (ev (myintegrand, y = k/10), k, 0, 60))));

seems to show the result from quad_qags is reasonable.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thank you Robert! I would never have figured this out on my own. I multiplied your expression in "myintegrand" by "%i" (there was an "i" just before the dy in my original expression but it was easy to miss!) and that resolved the missing minus sign. – Carey May 06 '21 at 21:18
  • Great, glad to hear it works. By the way, `quad_qags` returns a list of 4 elements, which represent the integral estimate, an estimate of the absolute error, the number of function evaluations, and an error code (from the library which it calls). `? quad_qags` says more about that. – Robert Dodier May 06 '21 at 21:58
  • Thanks for the helpful information about quad_qags! – Carey May 07 '21 at 00:47