Julia for MATLAB Users/Core Language/Mathematics

Mathematics edit

Most of the below functionality described in the core MATLAB Mathematics documentation has equivalent, often identical, functionality (more often that not with the same syntax) described in the Base.Mathematics section of the Julia manual. Specific equivalents are identified below; often these have the same names as in Matlab, otherwise the Julia equivalent name is noted.

Elementary Math edit

Arithmetic edit

See Arithmetic Operators in the Julia manual. Note that in Julia the operators are themselves methods and can be used anywhere a method can. See e.g. the example in the documentation for Base.map.

plus Addition edit

uplus Unary plus edit

minus Subtraction edit

uminus Unary minus edit

times Element-wise multiplication edit

rdivide Right array division edit

ldivide Left array division edit

power Element-wise power edit

mtimes Matrix Multiplication edit

mrdivide Solve systems of linear equations   for   edit

mldivide Solve systems of linear equations   for   edit

mpower Matrix power edit

cumprod Cumulative product edit

cumsum Cumulative sum edit

diff Differences and Approximate Derivatives edit

movsum Moving sum edit

prod Product of array elements edit

sum Sum of array elements edit

ceil Round toward positive infinity edit

fix Round toward zero edit

floor Round toward negative infinity edit

idivide Integer division with rounding option edit

mod Remainder after division (modulo operation) edit

rem Remainder after division edit

round Round to nearest decimal or integer edit

bsxfun Apply element-wise operation to two arrays with implicit expansion enabled edit

Trigonometry edit

See Trigonometric and Hyperbolic functions in the Julia manual.

sin Sine of argument in radians edit

sind Sine of argument in degrees edit

asin Inverse sine in radians edit

asind Inverse sine in degrees edit

sinh Hyperbolic sine of argument in radians edit

asinh Inverse hyperbolic sine edit

cos Cosine of argument in radians edit

cosd Cosine of argument in degrees edit

acos Inverse cosine in radians edit

acosd Inverse cosine in degrees edit

cosh Hyperbolic cosine edit

acosh Inverse hyperbolic cosine edit

tan Tangent of argument in radians edit

tand Tangent of argument in degrees edit

atan Inverse tangent in radians edit

atand Inverse tangent in degrees edit

atan2 Four-quadrant inverse tangent edit

atan2d Four-quadrant inverse tangent in degrees edit

tanh Hyperbolic tangent edit

atanh Inverse hyperbolic tangent edit

csc Cosecant of input angle in radians edit

cscd Cosecant of argument in degrees edit

acsc Inverse cosecant in radians edit

acscd Inverse cosecant in degrees edit

csch Hyperbolic cosecant edit

acsch Inverse hyperbolic cosecant edit

sec Secant of angle in radians edit

secd Secant of argument in degrees edit

asec Inverse secant in radians edit

asecd Inverse secant in degrees edit

sech Hyperbolic secant edit

asech Inverse hyperbolic secant edit

cot Cotangent of angle in radians edit

cotd Cotangent of argument in degrees edit

acot Inverse cotangent in radians edit

acotd Inverse cotangent in degrees edit

coth Hyperbolic cotangent edit

acoth Inverse hyperbolic cotangent edit

hypot Square root of sum of squares (hypotenuse) edit

deg2rad Convert angle from degrees to radians edit

rad2deg Convert angle from radians to degrees edit

Exponents and Logarithms edit

See Powers, logs and roots in the Julia manual.

exp Exponential edit

expm1 Compute   accurately for small values of x edit

log Natural logarithm edit

log10 Common logarithm (base 10) edit

log1p Compute log(1+x) accurately for small values of x edit

log2 Base 2 logarithm and floating-point number dissection edit

nextpow2 Exponent of next higher power of 2 edit

nthroot Real nth root of real numbers edit

pow2 Base 2 power and scale floating-point numbers edit

reallog Natural logarithm for nonnegative real arrays edit

realpow Array power for real-only output edit

realsqrt Square root for nonnegative real arrays edit

sqrt Square root edit

Complex Numbers edit

See Complex Numbers in the Julia manual.

abs Absolute value and complex magnitude edit

angle Phase angle edit

complex Create complex array edit

conj Complex conjugate edit

cplxpair Sort complex numbers into complex conjugate pairs edit

i Imaginary unit edit

imag Imaginary part of complex number edit

isreal Determine whether array is real edit

j Imaginary unit edit

real Real part of complex number edit

sign Sign function (signum function) edit

unwrap Correct phase angles to produce smoother phase plots edit

Discrete Math edit

Equivalents available in Julia Base edit

factorial Factorial of input edit
gcd Greatest common divisor edit
lcm Least common multiple edit

Equivalents available in JuliaMath/Primes.jl edit

factor Prime factors edit
primes Prime numbers less than or equal to input value edit
isprime Determine which array elements are prime edit
nchoosek Binomial coefficient or all combinations (Julia: binomial) edit

Others edit

perms All possible permutations edit

The Julia Permutations.permutations(a) function ( Permutations.jl package) returns an iterator object (because the number of permutations can be very large), and in lexicographic order rather than reverse lexicographic. Therefore a drop-in equivalent could be constructed as follows:

julia> perms(a) = reverse(collect(permutations(a)))
perms (generic function with 1 method)

julia> perms([2,4,6])
6-element Array{Array{Int64,1},1}:
 [6, 4, 2]
 [6, 2, 4]
 [4, 6, 2]
 [4, 2, 6]
 [2, 6, 4]
 [2, 4, 6]

rat Rational fraction approximation, rats Rational output edit

There doesn't appear to be a direct Julia equivalent of these, but note that unlike Matlab, Julia has a native Rational Number type .

Polynomials edit

See the Polynomials.jl package. Note that this package provides a proper type for polynomials, Polynomials.Poly, while in Matlab a polynomial of degree  is represented by a vector of length  whose elements are the coefficients in descending powers of the polynomial.

poly Polynomial with specified roots or characteristic polynomial edit

polyeig Polynomial eigenvalue problem edit

polyfit Polynomial curve fitting edit

Polynomials.polyfit provides comparable basic functionality--the single output argument form of the Matlab function--although it lacks the additional error estimate and centering/scaling features.

residue Partial fraction expansion (partial fraction decomposition) edit

roots Polynomial roots edit

Polynomials.roots provides roots with multiplicity.

polyval Polynomial evaluation edit

See Base.Math.@evalpoly in the Julia Manual.

polyvalm Matrix polynomial evaluation edit

conv Convolution and polynomial multiplication edit

deconv Deconvolution and polynomial division edit

polyint Polynomial integration edit

polyder Polynomial differentiation edit

Special Functions edit

airy Airy Functions edit

besselh Bessel function of third kind (Hankel function) edit

besseli Modified Bessel function of first kind edit

besselj Bessel function of first kind edit

besselk Modified Bessel function of second kind edit

bessely Bessel function of second kind edit

beta Beta function edit

betainc Incomplete beta function edit

betaincinv Beta inverse cumulative distribution function edit

betaln Logarithm of beta function edit

ellipj Jacobi elliptic functions edit

ellipke Complete elliptic integrals of first and second kind edit

erf Error function edit

erfc Complementary error function edit

erfcinv Inverse complementary error function edit

erfcx Scaled complementary error function edit

erfinv Inverse error function edit

expint Exponential integral edit

gamma Gamma function edit

gammainc Incomplete gamma function edit

gammaincinv Inverse incomplete gamma function edit

gammaln Logarithm of gamma function edit

legendre Associated Legendre functions edit

psi Psi (polygamma) function edit

Cartesian Coordinate System Conversion edit

cart2pol Transform Cartesian coordinates to polar or cylindrical edit

cart2sph Transform Cartesian coordinates to spherical edit

pol2cart Transform polar or cylindrical coordinates to Cartesian edit

sph2cart Transform spherical coordinates to Cartesian edit

Constants and Test Matrices edit

Constants edit

See General Number Functions and Constants in the Julia manual.

eps Floating-point relative accuracy edit

flintmax Largest consecutive integer in floating-point format edit

i, j Imaginary unit edit

In Julia, im is equivalent; this allows i and j to be used as e.g. loop indices without conflict.

Inf Infinity edit

pi Ratio of circle's circumference to its diameter edit

Also available as pi in Julia as well as \piTab ↹ 

NaN Not-a-Number edit

isfinite Array elements that are finite edit

isinf Array elements that are infinite edit

isnan Array elements that are NaN edit

compan Companion matrix edit

Test Matrices edit

See the MatrixDepot.jl package; most of the matrices in gallery and all the rest below are available in that package, plus some additional ones.

gallery Test matrices edit

hadamard Hadamard matrix edit

hankel Hankel matrix edit

hilb Hilbert matrix edit

invhilb Inverse of Hilbert matrix edit

magic Magic square edit

pascal Pascal matrix edit

rosser Classic symmetric eigenvalue test problem edit

toeplitz Toeplitz matrix edit

vander Vandermonde matrix edit

wilkinson Wilkinson's eigenvalue test matrix edit

Linear Algebra edit

See Linear Algebra in the Julia manual.

mldivide Solve systems of linear equations   for   edit

mrdivide Solve systems of linear equations   for   edit

decomposition Matrix decomposition for solving linear systems edit

lsqminnorm Minimum norm least-squares solution to linear equation edit

linsolve Solve linear system of equations edit

inv Matrix inverse edit

pinv Moore-Penrose pseudoinverse edit

lscov Least-squares solution in presence of known covariance edit

lsqnonneg Solve nonnegative linear least-squares problem edit

sylvester Solve Sylvester equation   for   edit

eig Eigenvalues and eigenvectors edit

eigs Subset of eigenvalues and eigenvectors edit

balance Diagonal scaling to improve eigenvalue accuracy edit

svd Singular value decomposition edit

svds Subset of singular values and vectors edit

gsvd Generalized singular value decomposition edit

ordeig Eigenvalues of quasitriangular matrices edit

ordqz Reorder eigenvalues in QZ factorization edit

ordschur Reorder eigenvalues in Schur factorization edit

polyeig Polynomial eigenvalue problem edit

qz QZ factorization for generalized eigenvalues edit

hess Hessenberg form of matrix edit

schur Schur decomposition edit

rsf2csf Convert real Schur form to complex Schur form edit

cdf2rdf Convert complex diagonal form to real block diagonal form edit

lu LU matrix factorization edit

ldl Block LDL' factorization for Hermitian indefinite matrices edit

chol Cholesky factorization edit

cholupdate Rank 1 update to Cholesky factorization edit

qr Orthogonal-triangular decomposition edit

qrdelete Remove column or row from QR factorization edit

qrinsert Insert column or row into QR factorization edit

qrupdate Rank 1 update to QR factorization edit

planerot Givens plane rotation edit

transpose Transpose vector or matrix edit

ctranspose Complex conjugate transpose edit

mtimes Matrix Multiplication edit

mpower Matrix power edit

sqrtm Matrix square root edit

expm Matrix exponential edit

logm Matrix logarithm edit

funm Evaluate general matrix function edit

kron Kronecker tensor product edit

cross Cross product edit

dot Dot product edit

bandwidth Lower and upper matrix bandwidth edit

tril Lower triangular part of matrix edit

triu Upper triangular part of matrix edit

isbanded Determine if matrix is within specific bandwidth edit

isdiag Determine if matrix is diagonal edit

ishermitian Determine if matrix is Hermitian or skew-Hermitian edit

issymmetric Determine if matrix is symmetric or skew-symmetric edit

istril Determine if matrix is lower triangular edit

istriu Determine if matrix is upper triangular edit

norm Vector and matrix norms edit

normest 2-norm estimate edit

vecnorm Vector-wise norm edit

cond Condition number for inversion edit

condest 1-norm condition number estimate edit

rcond Reciprocal condition number edit

condeig Condition number with respect to eigenvalues edit

det Matrix determinant edit

null Null space edit

orth Orthonormal basis for range of matrix edit

rank Rank of matrix edit

rref Reduced row echelon form (Gauss-Jordan elimination) edit

trace Sum of diagonal elements edit

subspace Angle between two subspaces edit

Random Number Generation edit

rand Uniformly distributed random numbers edit

randn Normally distributed random numbers edit

randi Uniformly distributed pseudorandom integers edit

randperm Random permutation edit

rng Control random number generation edit

randStream Random number stream edit

Interpolation edit

interp1 1-D data interpolation (table lookup) edit

interp2 Interpolation for 2-D gridded data in meshgrid format edit

interp3 Interpolation for 3-D gridded data in meshgrid format edit

interpn Interpolation for 1-D, 2-D, 3-D, and N-D gridded data in ndgrid format edit

gRiddedinterpolant Gridded data interpolation edit

pchip Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) edit

spline Cubic spline data interpolation edit

ppval Evaluate piecewise polynomial edit

mkpp Make piecewise polynomial edit

unmkpp Extract piecewise polynomial details edit

padecoef Padé approximation of time delays edit

interpft 1-D interpolation (FFT method) edit

ndgrid Rectangular grid in N-D space edit

meshgrid 2-D and 3-D grids edit

griddata Interpolate 2-D or 3-D scattered data edit

griddatan Interpolate N-D scattered data edit

scaTteredinterpolant Interpolate 2-D or 3-D scattered data edit

Optimization edit

fminbnd Find minimum of single-variable function on fixed interval edit

fminsearch Find minimum of unconstrained multivariable function using derivative-free method edit

lsqnonneg Solve nonnegative linear least-squares problem edit

fzero Root of nonlinear function edit

optimget Optimization options values edit

optimset Create or edit optimization options structure edit

Numerical Integration and Differential Equations edit

See DifferentialEquations.jl. In particular see the section Translations from MATLAB/Python/R.

Ordinary Differential Equations edit

ode45 Solve nonstiff differential equations — medium order method edit

ode23 Solve nonstiff differential equations — low order method edit

ode113 Solve nonstiff differential equations — variable order method edit

ode15s Solve stiff differential equations and DAEs — variable order method edit

ode23s Solve stiff differential equations — low order method edit

ode23t Solve moderately stiff ODEs and DAEs — trapezoidal rule edit

ode23tb Solve stiff differential equations — trapezoidal rule + backward differentiation formula edit

ode15i Solve fully implicit differential equations — variable order method edit

decic Compute consistent initial conditions for ode15i edit

odeget Extract ODE option values edit

odeset Create or modify options structure for ODE solvers edit

deval Evaluate differential equation solution structure edit

odextend Extend solution to ODE edit

Boundary Value Problems edit

bvp4c Solve boundary value problems for ordinary differential equations edit

bvp5c Solve boundary value problems for ordinary differential equations edit

bvpinit Form initial guess for BVP solvers edit

bvpxtend Form guess structure for extending boundary value solutions edit

bvpget Extract properties from options structure created with bvpset edit

bvpset Create or alter options structure of boundary value problem edit

deval Evaluate differential equation solution structure edit

Delay Differential Equations edit

dde23 Solve delay differential equations (DDEs) with constant delays edit

ddesd Solve delay differential equations (DDEs) with general delays edit

ddensd Solve delay differential equations (DDEs) of neutral type edit

ddeget Extract properties from delay differential equations options structure edit

ddeset Create or alter delay differential equations options structure edit

deval Evaluate differential equation solution structure edit

Partial Differential Equations edit

pdepe Solve initial-boundary value problems for parabolic-elliptic PDEs in 1-D edit

pdeval Evaluate numerical solution of PDE using output of pdepe edit

Numerical Integration and Differentiation edit

integral Numerical integration edit

integral2 Numerically evaluate double integral edit

integral3 Numerically evaluate triple integral edit

quadgk Numerically evaluate integral, adaptive Gauss-Kronrod quadrature edit

quad2d Numerically evaluate double integral, tiled method edit

cumtrapz Cumulative trapezoidal numerical integration edit

trapz Trapezoidal numerical integration edit

polyint Polynomial integration edit

del2 Discrete Laplacian edit

diff Differences and Approximate Derivatives edit

gradient Numerical gradient edit

polyder Polynomial differentiation edit

Fourier Analysis and Filtering edit

fft Fast Fourier transform edit

fft2 2-D fast Fourier transform edit

fftn N-D fast Fourier transform edit

fftshift Shift zero-frequency component to center of spectrum edit

fftw Define method for determining FFT algorithm edit

ifft Inverse fast Fourier transform edit

ifft2 2-D inverse fast Fourier transform edit

ifftn Multidimensional inverse fast Fourier transform edit

ifftshift Inverse zero-frequency shift edit

nextpow2 Exponent of next higher power of 2 edit

interpft 1-D interpolation (FFT method) edit

conv Convolution and polynomial multiplication edit

conv2 2-D convolution edit

convn N-D convolution edit

deconv Deconvolution and polynomial division edit

filter 1-D digital filter edit

filter2 2-D digital filter edit

ss2tf Convert state-space representation to transfer function edit

padecoef Padé approximation of time delays edit

Sparse Matrices edit

spalloc Allocate space for sparse matrix edit

spdiags Extract and create sparse band and diagonal matrices edit

speye Sparse identity matrix edit

sprand Sparse uniformly distributed random matrix edit

sprandn Sparse normally distributed random matrix edit

sprandsym Sparse symmetric random matrix edit

sparse Create sparse matrix edit

spconvert Import from sparse matrix external format edit

issparse Determine whether input is sparse edit

nnz Number of nonzero matrix elements edit

nonzeros Nonzero matrix elements edit

nzmax Amount of storage allocated for nonzero matrix elements edit

spfun Apply function to nonzero sparse matrix elements edit

spones Replace nonzero sparse matrix elements with ones edit

spparms Set parameters for sparse matrix routines edit

spy Visualize sparsity pattern edit

find Find indices and values of nonzero elements edit

full Convert sparse matrix to full matrix edit

dissect Nested dissection permutation edit

amd Approximate minimum degree permutation edit

colamd Column approximate minimum degree permutation edit

colperm Sparse column permutation based on nonzero count edit

dmperm Dulmage-Mendelsohn decomposition edit

randperm Random permutation edit

symamd Symmetric approximate minimum degree permutation edit

symrcm Sparse reverse Cuthill-McKee ordering edit

pcg Preconditioned conjugate gradients method edit

minres Minimum residual method edit

symmlq Symmetric LQ method edit

gmres Generalized minimum residual method (with restarts) edit

bicg Biconjugate gradients method edit

bicgstab Biconjugate gradients stabilized method edit

bicgstabl Biconjugate gradients stabilized (l) method edit

cgs Conjugate gradients squared method edit

qmr Quasi-minimal residual method edit

tfqmr Transpose-free quasi-minimal residual method edit

lsqr LSQR method edit

ichol Incomplete Cholesky factorization edit

ilu Incomplete LU factorization edit

eigs Subset of eigenvalues and eigenvectors edit

svds Subset of singular values and vectors edit

normest 2-norm estimate edit

condest 1-norm condition number estimate edit

sprank Structural rank edit

etree Elimination tree edit

symbfact Symbolic factorization analysis edit

spaugment Form least-squares augmented system edit

dmperm Dulmage-Mendelsohn decomposition edit

etreeplot Plot elimination tree edit

treelayout Lay out tree or forest edit

treeplot Plot picture of tree edit

gplot Plot nodes and links representing adjacency matrix edit

unmesh Convert edge matrix to coordinate and Laplacian matrices edit

Graph and Network Algorithms edit

graph Graph with undirected edges edit

digraph Graph with directed edges edit

addnode Add new node to graph edit

rmnode Remove node from graph edit

addedge Add new edge to graph edit

rmedge Remove edge from graph edit

flipedge Reverse edge directions edit

numnodes Number of nodes in graph edit

numedges Number of edges in graph edit

findnode Locate node in graph edit

findedge Locate edge in graph edit

edgecount Number of edges between two nodes edit

reordernodes Reorder graph nodes edit

subgraph Extract subgraph edit

bfsearch Breadth-first graph search edit

dfsearch Depth-first graph search edit

centrality Measure node importance edit

maxflow Maximum flow in graph edit

conncomp Connected graph components edit

biconncomp Biconnected graph components edit

condensation Graph condensation edit

bctree Block-cut tree graph edit

minspantree Minimum spanning tree of graph edit

toposort Topological order of directed acyclic graph edit

isdag Determine if graph is acyclic edit

transclosure Transitive closure edit

transreduction Transitive reduction edit

isisomorphic Determine whether two graphs are isomorphic edit

isomorphism Compute isomorphism between two graphs edit

ismultigraph Determine whether graph has multiple edges edit

simplify Reduce multigraph to simple graph edit

shortestpath Shortest path between two single nodes edit

shortestpathtree Shortest path tree from node edit

distances Shortest path distances of all node pairs edit

adjacency Graph adjacency matrix edit

incidence Graph incidence matrix edit

laplacian Graph Laplacian matrix edit

degree Degree of graph nodes edit

neighbors Neighbors of graph node edit

nearest Nearest neighbors within radius edit

indegree In-degree of nodes edit

outdegree Out-degree of nodes edit

predecessors Node predecessors edit

successors Node successors edit

inedges Incoming edges to node edit

outedges Outgoing edges from node edit

plot Plot graph nodes and edges edit

labeledge Label graph edges edit

labelnode Label graph nodes edit

layout Change layout of graph plot edit

highlight Highlight nodes and edges in plotted graph edit

graphPlot Graph plot for directed and undirected graphs edit

Computational Geometry edit

See the JuliaGeometry GitHub organization.

Triangulation Representation edit

triangulation Triangulation in 2-D or 3-D edit

tetramesh Tetrahedron mesh plot edit

trimesh Triangular mesh plot edit

triplot 2-D triangular plot edit

trisurf Triangular surface plot edit

Delaunay Triangulation edit

deLaunaytriangulation Delaunay triangulation in 2-D and 3-D edit

delaunay Delaunay triangulation edit

delaunayn N-D Delaunay triangulation edit

tetramesh Tetrahedron mesh plot edit

trimesh Triangular mesh plot edit

triplot 2-D triangular plot edit

trisurf Triangular surface plot edit

Spatial Search edit

triangulation Triangulation in 2-D or 3-D edit

deLaunaytriangulation Delaunay triangulation in 2-D and 3-D edit

dsearchn N-D nearest point search edit

tsearchn N-D closest simplex search edit

delaunay Delaunay triangulation edit

delaunayn N-D Delaunay triangulation edit

Bounding Regions edit

boundary Boundary of a set of points in 2-D or 3-D edit

alphaShape Polygons and polyhedra from points in 2-D and 3-D edit

convhull Convex hull edit

convhulln N-D convex hull edit

Voronoi Diagram edit

patch Create one or more filled polygons edit

voronoi Voronoi diagram edit

voronoin N-D Voronoi diagram edit

Elementary Polygons edit

The Julia package GeometricalPredicates.jl provides some similar functionality.

inpolygon Points located inside or on edge of polygonal region edit

nsidedpoly Regular polygon edit

polyarea Area of polygon edit

polybuffer Create buffer around points or lines edit

rectint Rectangle intersection area edit

polyshape 2-D polygons edit

addboundary Add polyshape boundary edit

rmboundary Remove polyshape boundary edit

rmholes Remove holes in polyshape edit

rmslivers Remove polyshape boundary outliers edit

simplify Simplify polyshape boundaries edit

boundary Vertex coordinates of polyshape boundary edit

isequal Determine if polyshape objects are equal edit

ishole Determine if polyshape boundary is a hole edit

isinterior Query points inside polyshape edit

issimplified Determine if polyshape is well-defined edit

nearestvertex Query nearest polyshape vertex edit

numboundaries Number of polyshape boundaries edit

numsides Number of polyshape sides edit

overlaps Determine whether polyshape objects overlap edit

area Area of polyshape edit

boundingbox Bounding box of polyshape edit

centroid Centroid of polyshape edit

convhull Convex hull of polyshape edit

perimeter Perimeter of polyshape edit

triangulation Triangulate polyshape edit

turningdist Compute turning distance between polyshape objects edit

intersect Intersection of polyshape objects edit

subtract Difference of two polyshape objects edit

union Union of polyshape objects edit

xor Exclusive OR of two polyshape objects edit

polybuffer Buffer polyshape edit

rotate Rotate polyshape edit

scale Scale polyshape edit

translate Translate polyshape edit

holes Convert polyshape hole boundaries to array of polyshape objects edit

plot Plot polyshape edit

regions Access polyshape regions edit

sortboundaries Sort polyshape boundaries edit

sortregions Sort polyshape regions edit