Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maxima numerical integration syntax

Tags:

maxima

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!

like image 694
Carey Avatar asked Mar 09 '26 16:03

Carey


1 Answers

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.

like image 132
Robert Dodier Avatar answered Mar 11 '26 05:03

Robert Dodier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!