Search code examples
mathevaluationsymbolic-mathmaxima

How can I evaluate an integration to a number?


I have some functions set up like this:

f(x):=1-2**-x$
g(y):=integrate(f(x), x, 0, y)$

and evaluated them:

f(1)$float(%);
g(1)$float(%);

but for g(1), I got a symbolic answer instead of a numerical answer. Using float() was an attempt to get a numerical answer but it just turned all of the terms in the integral into floats.

How can I get g(1) as a number?


Solution

  • Why not just do (by the definition of definite integral):

    f(x):=1-2**-x$
    gg(x):=''(integrate(f(x), x))$
    g(y):=gg(y) - gg(0)$
    

    '' (quote-quote) operator is used to force the evaluation of the :='s right hand side before the assignment.