We have already seen that one way to convince Mathematica to give you a
floating-point answer is to use decimal points in all of your constants. But
that is not always convenient. For example, consider the following
calculation:
ArcCos[ 1/2 ] + ArcSin[ 1/2 ]
Another way to force Mathematica to give a floating-point answer is to use the N
function, which asks Mathematica to evaluate an expression to obtain a
floating-point number. For example:
N[ ArcCos[ 1/2 ] + ArcSin[ 1/2 ]]
N takes an optional second argument, which specifies the number
of digits of precision you'd like your answer to have. So we can easily
determine the first 100 digits of Pi:
N[ Pi, 100 ]
N also works with complex numbers by putting the real and imaginary
parts into floating point form. Thus, compare
Sqrt[ -127 ]
and
N[ Sqrt[ -127 ]]