pi
The constant pi, the ratio of a circle's circumference to its diameter.
Category: Mathematics > Elementary Math
Syntax
x = pi
Returns the double-precision value closest to pi, 3.141592653589793.
X = pi(n)
Returns an n-by-n matrix in which every element is pi.
X = pi(sz1, ..., szN)
Returns an array of the given size in which every element is pi.
Description
pi is a function, not a true constant, but it takes no arguments in normal use and is written without parentheses. It is a floating-point approximation: sin(pi) is about 1.2246e-16, not zero, because pi itself is slightly off. When exact results at multiples of pi matter, use the degree functions (sind, cosd) or sinpi and cospi.
Since pi can be overwritten by assigning a variable with that name, avoid using it as a variable.
Input arguments
n, sz1, ..., szN- Optional dimensions of the result.
Output arguments
x- Double value or array filled with pi.
Example
Area, angle conversion and rounding error
r = 2;
area = pi * r^2
rad2deg(pi/3)
sin(pi)
sinpi(1)
Output
area = 12.5664
ans = 60.0000
ans = 1.2246e-16
ans = 0