4

 

 

Matrix/Vector Calculations and Functions

 

Both platforms are designed to work natively with vectors and matrices. Many of the standard functions to perform basic mathematical calculations are vectorized, meaning they will operate on all elements of a vector or matrix. That is, you can write things like sqrt(v) to compute the square roots of all elements of vector v, or exp(A) to raise e to the power of each element of matrix A. In a non-vectorized platform like the C programming language, a for loop would be needed to iterate over the elements of the vector or matrix. In both R and MATLAB, that for loop is internal, running at the speed of code compiled to the native computer language, and therefore runs much more quickly than a loop ...

Get R and MATLAB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.