|
Connecting to Matlab Two Options For Windows Users
Two Options For Mac Users
Using Matlab
The matlab prompt looks like this: >>
>> A = [1 4 -6; 7 6 2; -2 1 0]
>> A(1, 1) = -5 changes the element in row1 column1 of matrix A to -5 >> D(2, :) = 0 changes all elements in row2 of matrix D to 0 >> A(1:3, 3)=[7,8,9] changes the elements in col 3 to 7,8,9. >> X=A(:, 3) extracts column 3 from the matrix A and puts the values in a column matrix called X
Examples: >> A + A adds the matrix A to itself. >> B * C multiplies B and C >> C*B - A A is subtracted from the product of C and B The symbol ^ (above the number 6) is used to raise a matrix to an exponent as follows: >> A^3 cubes the matrix A ( you might also use A*A*A for the same calculation) >> C*D an error message is displayed Matlab will give an error message when the calculation cannot be done because of a dimension mismatch.
quit or exit either of these
closes the program and ends your matlab session. save filename this command will save all variables (and ONLY the variables - NOT the whole session) that you have defined in the current session. This is helpful when you enter large matrices that you want to work with at a later date. load filename this command loads the
variables that you saved in a previous session. who displays variables you have defined in your current session clear clears all variables from your current
session. Only use this command if you want to lose everything. % this is used for comments. Matlab ignores any line that begins with %
>> size(A) gives the dimension of the matrix A >> inv(A) calculates the inverse of the matrix A , if it exists. >> det(A) calculates the determinant of the matrix A >> rref(A) calculates the row reduced echelon form of the matrix A >> A' forms the transpose of the matrix A. >> eye (2,2) this is the 2 by 2 identity >> zeros (3,3) builds the zero matrix of any dimension >> rats (A) writes elements of matrix
A as fractions. augmented matrix - - you can create an augmented
matrix from two others that you have already defined as follows: >> S = [ A C] uses the matrix A and C defined previously and creates the matrix S >> format long displays all numbers with 15 digits instead of the usual 4 digits >> eig(A) gives the eigenvalues of the matrix A >> poly(A) gives the coefficients of the characteristic polynomial A. The roots of this polynomial are the eigenvalues of A. |