This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

N

N[expr]
gives the numerical value of expr.
N
attempts to give a result with n-digit precision.
  • Unless numbers in expr are exact, or of sufficiently high precision, N may not be able to give results with n-digit precision.
  • N may internally do computations to more than n digits of precision.
  • $MaxExtraPrecision specifies the maximum number of extra digits of precision that will ever be used internally.
  • The precision n is given in decimal digits; it need not be an integer.
  • N gives the number with machine precision.
  • N converts each successive argument of any function it encounters to numerical form, unless the head of the function has an attribute such as NHoldAll.
  • You can define numerical values of functions using N[f[args]]:=value and N[f[args], n]:=value.
  • N attempts to generate a result with precision at most p and accuracy at most a.
  • N[expr, {Infinity, a}] attempts to generate a result with accuracy a.
  • N[expr, {Infinity, 1}] attempts to find a numerical approximation to the integer part of expr.
Evaluate numerically:
Evaluate numerically to 50-digit precision:
With machine-precision input, the results are always machine precision:
With exact input, the results can be to the precision specified:
Evaluate numerically:
In[1]:=
Click for copyable input
Out[1]=
 
Evaluate numerically to 50-digit precision:
In[1]:=
Click for copyable input
Out[1]=
 
With machine-precision input, the results are always machine precision:
In[1]:=
Click for copyable input
Out[1]=
With exact input, the results can be to the precision specified:
In[2]:=
Click for copyable input
Out[2]=
Evaluate mathematical constants to any precision:
Get approximate values for large integers:
Complex number results:
More elaborate symbolic mathematical constants can be detected using NumericQ:
In general, NumericQ expressions represent numbers that can be evaluated to any precision:
Evaluate the entries of a matrix numerically:
Evaluate numerically the numeric parts of a symbolic expression:
Make the coefficients of a polynomial numerical:
N[e] typically works by replacing numbers with machine numbers and computing the result:
This is equivalent to the expression with machine numbers:
The machine roundoff error shows up clearly on a log-log plot of the difference quotient error:
N works adaptively using arbitrary-precision numbers when p is not MachinePrecision:
With adaptive precision, the difference quotient error matches the theoretical value:
The adaptive precision control has a default limit, $MaxExtraPrecision, for extra precision:
When the limit is reached, you can locally increase $MaxExtraPrecision to resolve the difficulty:
N does not raise the precision of approximate numbers in its input:
The precision of the result is the same as that of the input:
You can use SetPrecision to increase the precision of input expressions:
N does not affect exact numeric powers:
The base is modified:
The power is modified if it is not NumericQ:
SparseArray objects are treated based on the represented array:
In general, N[Normal[s]] is identical to Normal:
Data objects like InterpolatingFunction have special rules so that only the data is affected:
Only the appropriate data has been changed so that the new function uses machine numbers:
Operations like Integrate use the corresponding N-functions when appropriate:
This is using NIntegrate:
For high requested precision, numerical algorithms may take a lot of time or need adjustment:
In this case you may want to use NIntegrate directly:
For most expressions, N affects the tree shown in FullForm:
The appears in front of because of how is represented:
The integers in have just been converted to machine numbers:
Prevent an indexed variable from being affected by N using the NHoldAll attribute:
With this, N only affects the coefficients:
Without this, N affects the indices too:
Define a numerical constant equal to :
In an exact symbolic expression the constant does not evaluate:
With N it does:
Add a definition that will work with arbitrary precision or accuracy:
Numerically evaluate an expression to accuracy 20:
Define a function that represents the real-valued root for positive and positive integer :
Prevent its second argument from being converted to real using NHoldRest:
An exact representation of the cube root of 2:
Machine-number approximation:
47-digit approximation:
Define a data object that represents a polynomial in a sparse form :
Make sure that N only affects the coefficients, not the powers:
Default N evaluation of the argument needs to be prevented for the rule to work:
A representation of the polynomial :
Get the representation with approximate real coefficients:
Evaluate at :
5-digit accuracy and any precision:
1-digit accuracy, corresponding to integer part only:
Get either 20-digit precision or 30-digit accuracy:
The result of N[e] generally has precision MachinePrecision:
If the result is too large for machine numbers the precision may be different:
The result of N generally has Precision equal to p:
When this is not possible, Mathematica will give a message:
Typically increasing $MaxExtraPrecision will resolve the problem:
For hidden zeros, positive precision is not achievable, so you may want to use accuracy:
The result of N generally has Accuracy equal to a:
When this is not possible Mathematica will give a message:
Typically increasing $MaxExtraPrecision will resolve the problem:
A -digit texture:
New in 1 | Last modified in 5