Matlab provides a host of elementary mathematical functions. To see the functions provided, type help elfun. Matlab evaluates the elementary functions component-wise.
Computing the exponential function
>> x = 0:10; exp(-x)
Matlab provides easily computed matrix functions. These include the measures of the matrix size, standard decompositions of the matrix, LU, QR and SVD, the eigenvalues and eigenvectors. To see the functions provided type help matfun.
Compute the eigenvalues of a symmetric matrix.
>> A = rand(4); A = A*A', eig(A) A = 1.5788 0.6565 1.2657 1.0939 0.6565 0.5826 0.4885 0.7305 1.2657 0.4885 1.0277 0.8001 1.0939 0.7305 0.8001 1.2804 ans = 0.0008 0.1217 0.5381 3.8089Compute the eigenvectors and eigenvalues.
>> A = rand(4); A = A*A', [V,D] = eig(A)
Compute the LU decomposition of a matrix
>> A = [4 1; 1 4], [L U] = lu(A) A = 4 1 1 4 L = 1.0000 0 0.2500 1.0000 U = 4.0000 1.0000 0 3.7500
Type help funfun, or help fsolve
Type odedemo, or try the following demonstration that solves the Lotka-Voltera equation from mathematical biology. The equations are
u' = u - 0.01 u v v' = -v + 0.02 u vTo see this code for this function type,
>> type lotkaAnd to solve the ODE, type
>> [t,y] = ode23('lotka',[0,15],[20,20]);To see the trajectories of the solution type
>> plot(t,y)And to see the phase plane type
>> plot(y(:,1),y(:,2))
Matlab provides fast fourier transformations based on complex exponential functions (fft, fft2 fftn), sine functions (dst, dst2) and cosine functions (dct, dct2). The inverse functions are preceeded by the letter i, for example ifft. Advance applications of FFT's are also available. These include the Hilbert transforms, filters, and spectrum analysis among others.
Compute the FFT and inverse FFT of a vector x.
>> x = rand(8,1) >> x_hat = fft(x) >> x2 = ifft(x_hat)
David Eyre