00-introtomatlab

download 00-introtomatlab

of 3

Transcript of 00-introtomatlab

  • 7/27/2019 00-introtomatlab

    1/3

    home > return to last page

    Introduction to MatlabIn addition to this page you may want a list of Matlab Help sites.

    Connecting to to Matlab

    You must first activate your mason account. This can be done online with your GMU ID (socialsecurity number) and your PIN. See the web page below for instructions to activate your account.https://mason.gmu.edu/ISO/SysEng/Mason/account.html

    If you are working at home you can access osf1/mason using your internet provider or direct dialup using the number: 703 426 - 2468 .

    Download Secure Shell from the mason website: http://itusupport.gmu.edu/downloads/index.asp Once you have it installed, open the program.From the SSH client window, click on the 'Quick Connect' button.In the Host Name Box type mason.gmu.edu and your user name.Press Connect and you will be prompted to enter your password. .The Mason prompt looks like either of these: osf1.gmu.edu>

    mason.gmu.edu>

    To begin your Matlab session, at the osf1/mason prompt type matlab and press enter.

    The matlab prompt looks like this: >>

    Copy from the SSH window by highlighting the text and right click to Copy (or use the editmenu). You can open notepad and paste the text there using the right click menu. This allows youto easily edit your work, erase errors, etc. before printing and turning in your assignment.

    Using Matlab

    To define a matrix you start with its name. Square brackets are used to begin and end eachmatrix. Commas separate the elements and you can press return to end each row.

    >> A = [1,4,-67,6,2-2,1,0]You can also separate elements with a space and end each row with a semi-colon like this:

    http://www.gmu.edu/http://math.gmu.edu/index.htmlhttp://math.gmu.edu/index.htmlhttp://history.go%28-1%29/http://history.go%28-1%29/http://history.go%28-1%29/http://bass.gmu.edu/matlab/matlab.htmlhttp://bass.gmu.edu/matlab/matlab.htmlhttp://bass.gmu.edu/matlab/matlab.htmlhttps://mason.gmu.edu/ISO/SysEng/Mason/account.htmlhttps://mason.gmu.edu/ISO/SysEng/Mason/account.htmlhttp://itusupport.gmu.edu/downloads/index.asphttp://itusupport.gmu.edu/downloads/index.asphttp://itusupport.gmu.edu/downloads/index.asphttp://www.gmu.edu/http://itusupport.gmu.edu/downloads/index.asphttps://mason.gmu.edu/ISO/SysEng/Mason/account.htmlhttp://bass.gmu.edu/matlab/matlab.htmlhttp://history.go%28-1%29/http://math.gmu.edu/index.html
  • 7/27/2019 00-introtomatlab

    2/3

    >> A = [1 4 -6; 7 6 2; -2 1 0;]In either case you have defined the same 3 by 3 matrix named A and you can use it at any time ina calculation or to define another matrix by using its name (A).

    Examples: >> B = [2 -4 7 ] B is a 1 by 3 row matrix

    >> C = [2; -4; 7; ] C is a 3 by 1 column matrix

    >>D = [ 5,8,-2;3,-4,5] D is a 2 by 3 matrix

    You can edit individual elements of a matrix as follows:

    >> A(1,1) = -5 changes the element in row1 column1 of matrix A to -5>> D(2,3) = 0 changes the element in row2 column3 of matrix D to 0

    >> X=A(1:3,3) this will extract the third column of A (rows 1-3) and put it into a matrix calledX.

    To perform operations on matrices you use the symbols ( +, -, * ) from the number keypad or above the numbers across the top of the keyboard.

    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 BThe 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 calculationcannot be done because of a dimension mismatch.

    Here are some basic matlab commands that you will need:

    quit or exit either of these closes the program and ends your matlab session.save filename this command will save all variables 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.diary filename if you are using a Unix terminal, you must use this command before you can

    print your work. The file you create will be saved in your home directory.diary off the diary file starts at the point where you insert the command diary and ends whereyou type diary off . (This allows you to control what gets saved in the diary file.)lpr this is the command used to print your diary file. EXIT THE MATLAB PROGRAM.At the osf1 prompt, type: lpr -Pst220 filename (note: st220 is the printer in ST I room 220. Atother locations you will use another printer name after the - P )who displays variables you have defined in your current sessionwhy matlab answers the question.(again and again)

  • 7/27/2019 00-introtomatlab

    3/3