Evaluating log(x)



Andrew Martin <mr.a.martin at gmail.com> writes:

> I have an expression including log().
>
> 2*(1/2 - log(2)/2);
>
> How can I make maxima evaluate the expression (hence returning approx 0.307)?
>
> I've looked at the log simplification flags, simp and ev, but they
> don't seem to have the effect I want.
>
> Cheers,
>
> Andrew

You need to tell Maxima that you want a floating point number. After
all, if you want to keep the exact "log(2)" in the answer, then 1-log(2)
is as simple as it gets. To force floating point evaluation, use the
"float" function:

(%i1) 2*(1/2 - log(2)/2);
                                   1   log(2)
(%o1)                           2 (- - ------)
                                   2     2
(%i2) float(%o1);
(%o2)                          .3068528194400547

Another option is to use the "numer" flag for the implicit "ev" on the
command line:

(%i6) %o1, numer;
(%o6)                          .3068528194400547

Oddly enough, there is also a "float" flag, but this doesn't do what you
want, just converting all ratios to floats:

(%i7) %o1, float;
(%o7)                        2 (0.5 - 0.5 log(2))

Note that if the inside of the log call had not been an integer, "float"
would have behaved as expected:

(%i12) 2*(1/2 - log(2/3)/2), float;
(%o12)                         1.405465108108164

This is because the float flag converted the 2/3 to 0.66..7 and then log
of a floating point argument is simplified to the relevant
number. Confusing!

I confess my approach with this sort of thing is to write "%, float"
then swear and write "%, numer" if necessary...

Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20120821/7ea332c2/attachment.pgp>;