lettura simple

Mathematical Constants in Matlab

To simplify calculations in Matlab, some mathematical constants are predefined.

For example, the value of the Greek letter pi (π) is assigned to the constant "pi".

>> pi
ans = 3.1416

The Euler's number (e) can be obtained using the function exp(1).

>> exp(1)
ans = 2.7183

The constant Inf indicates the symbol for infinity ( ∞ ).

>> 1+Inf
ans = Inf

The imaginary unit of complex numbers is assigned by default to the letters i and j.

>>i
ans = 0.0000 + 1.0000i

>>j
ans = 0.0000 + 1.0000i

To denote the imaginary unit, two different letters are employed since "i" is commonly used in mathematical texts while "j" is used in engineering literature.

Note that Matlab does not prevent you from using the letters pi, i, j as session variables. For example, if you type pi=2 in the command line, the new value (2) overwrites the previous one (3.1416).
An example of assignment to mathematical constants.
If you assign a new value to the constant "pi" during the session, you won't be able to use it anymore to obtain the value of pi. I strongly suggest that you avoid doing this, as using the variable "pi" as the value of pi in other parts of the program could lead to massive calculation errors. The same advice applies to other predefined mathematical constants, such as "i," "j," and "Inf." So, never use these letters as session variables.

Another useful symbol in mathematical calculations is NaN, which means "Not A Number".

This symbol appears when the result of a mathematical operation is indeterminate.

For example, if you perform the operation zero divided by zero, Matlab returns NaN as the output.

>> 0/0
ans = NaN




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin