User:Eml4500.f08.gravy.bje

This is my wikipedia page for the Fall 2008 semester for EML4500

MatLab Tutorial
1. Accessing MATLAB

After MATLAB is installed to the computer, it may be accessed either by clicking on a icon on the desktop, or if that icon was not created, by selecting the icon in the start menu. An alternate method to access MATLAB is to enter it into the system command which can also be found in the start menu

For convenience, MATLAB, as well as the local editor should both remain open in separate windows for any computer system that allows for multiple processes. Any questions in this area should be directed towards the computer manufacturer.

2. Entering Matrices

Matrices are the method by which MATLAB represents all variables. Single variables or interpreted as a 1 x 1 matrix, with no indicated direction. This is also known as a scalar quantity. A vector is represented by any matrix consisting of one column, or one row. All matrices are two dimensional and must consist of numerical values.

There are multiple methods by which to introduce a matrix into MATLAB including loading the matrix from a disk or file, inserting the matrix manually, or using a matrix that has been generated by another mathematical equation. The following two statements are examples of the correct syntax to generate a 3 x 3 matrix:

A = [1 2 3; 4 5 6; 7 8 9]

A= [ 1 2 3 4 5 6 7 8 9] The first example separates the values by spaces and the rows by semi-colons while the second separates the rows by lines.

To indicate an exponent, values must be entered in without spaces (i.e. 2.34e-5) for proper syntax. MATLAB also has the ability to interpret imaginary numbers using i and j. These values are also entered without spaces (i.e. 3+4i). If the values of i and j are assigned prior to their use as an imaginary value, a new value can be used by first setting it equal to the square root of negative one.

If a matrix is too long and tedious to enter manually it should be entered via an ASCII file from the local editor to avoid possible error from input. To load files in MATLAB, use the load command followed by the name of the file.

For example: load filename.ext If a user wishes to experiment with matrices of random numbers the rand, magic, and hilb functions provide a solution. The rand function creates a matrix of randomly generated numbers for a matrix with the same number of rows as columns. The magic function creates a magic square matrix. This is a particular type of matrix where the rows, columns, and diagonals have a common sum. The hilb function creates a Hilbert matrix.

3. Matrix and Array Operations

MATLAB has a variety of operations available including addition (+), subtraction (-), multiplication (*), power (^), conjugate transpose (‘), left division (\), and right division (/) all of which can be applied to both scalars and vectors. Order of operations applies.

7. Scalar Functions

There are some functions in MATLAB that were designed and created for scalar functions. These functions can still operate element-wise on matrices. Some common examples are sin, cos, tan, asin, acos, atan, exp, log, ln, rem (remainder), abs (absolute value), sqrt (square root)

8. Vector Functions

Unlike scalar functions, vector functions are, as their name hints, used on vectors (i.e. matrices or size m x n). These functions when used yield answers which are also in vector form. Some common examples of vector functions are max (max value), min (min value), sort (sort values), median, mean, std (standard deviation), sum, prod (product)

9. Matrix Functions

As mentioned above, matrices are used as a representation of variables in MATLAB. This is what makes the program such a useful tool. Some common examples of matrix functions are eig (eigenvalues), chol (choleski factorization), inv (inverse), hess (hessenberg form), det (determinant)

Eigenvalues: eig Cholesky factorization: chol Inverse: inv Hessenberg form: hess Determinant: det

19. Sparse Matrix Computations

There are two storage modes in Matlab for a matrix: full and sparse. Full mode stores everything, while sparse only stores nonzero numbers. The default is to store elements of a matrix in full mode. In full mode, the zero elements are taken into account during calculations. Sparse mode will remove these zero elements during calculations, thus reducing time spent performing them. It saves time, but still outputs the same numbers.

Matrices can be converted between sparse and full fairly easily. The command “S=sparse(F)” will convert the full matrix, F, to a sparse matrix, S. It can then be converted back from sparse to full using the command "F=full(S)”.  Usually though, if a sparse matrix is desired, it will be created directly rather than by converting from a full matrix.  There are sparse analogs to many full matrices.  The fuctions speye, sparse, spones, and sprandn are sparse analogs to the full functions eye, zeros, ones and randn respectively.

When performing calculations using both full and sparse matrices, the storage mode of the output will vary. If calculations are performed on only sparse functions, the output will be sparse. If calculations are performed only on full functions, the output will be full. However, if calculations are performed using both full and sparse functions, the output will always come out as full unless the user specifically states otherwise.

Homework 1
Insert HW 1 here