Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Numerical integration with maxima

170 views
Skip to first unread message

Claude

unread,
Nov 6, 2012, 5:46:54 AM11/6/12
to
Dear readers

I would like to numerically integrate the function abs(sin(x)) over the
domain 0 to 2*pi.

I've defined the function
f=abs(sin(x))

and then I called

integrate(f, x, 0, 2*pi)

But now I don't know how to numerically evaluate this integral.

Manually, it is easy to see that the result should be 4, but how to ask
maxima to compute this ?

Similarly, I cannot plot this function over the same domain. I've tried :

wxplot2d([abs(sin(x))], [x,0,6.28])$

which gives the expected graph, but, if I replace the value 6.28 by 2*pi,
wxmaxima says that

plotting: range must be of the form [variable, min, max]; found: [x,0,2*pi]


Can you please give me some advice?

Thank you in advance for your help


Nasser M. Abbasi

unread,
Nov 6, 2012, 10:05:22 AM11/6/12
to
fyi;

If you do not get answer here (I myself do not use Maxima) you
can try the Maxima mailing list

http://maxima.sourceforge.net/maximalist.html

James Cloos

unread,
Nov 6, 2012, 1:54:41 PM11/6/12
to
>>>>> "C" == Claude <cla...@nospam.invalid> writes:

Just a couple of notes:

C> I've defined the function
C> f=abs(sin(x))

Use either:

f:abs(sin(x));

or:

f(x):=abs(sin(x));

C> integrate(f, x, 0, 2*pi)

Use 2*%pi.

C> But now I don't know how to numerically evaluate this integral.

More importantly, integrate() is for symbolic integration. For
numerical integration use quad_qag() and the related functions.

Try:

quad_qag(abs(sin(x)), x, 0, 2*%pi, 2);

for a 2nd order approximation. I get the result:

[4.0, 4.440892098500626e-14, 63, 0]

the values in the list are theapproximation, the approx error, the
number of evaluations and an error code. 0 means no error. So the
result is 4.0 +- 4.440892098500626e-14.

Try:

? quad_qag

and:

?? QUADPACK

in maxima.

Or read the QUADPACK sections of the info or printable manual.

-JimC
--
James Cloos <cl...@jhcloos.com> OpenPGP: 1024D/ED7DAEA6

Richard Fateman

unread,
Nov 6, 2012, 8:19:11 PM11/6/12
to
On 11/6/12 2:46 AM, Claude wrote:
> Dear readers
>
> I would like to numerically integrate the function abs(sin(x)) over the
> domain 0 to 2*pi.
use %pi


Claude

unread,
Nov 7, 2012, 3:21:28 PM11/7/12
to
Thank you all for your help !

claude
0 new messages