1 / 39

Lecture 20: Choosing the Right Tool for the Job

Lecture 20: Choosing the Right Tool for the Job. What is MATLAB?. MATLAB is one of a number of commercially available, sophisticated mathematical computation tools . Others include Maple Mathematica MathCad. MATLAB Excels at. Numerical calculations Especially involving matrices Graphics

andrer
Download Presentation

Lecture 20: Choosing the Right Tool for the Job

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 20: Choosing the Right Tool for the Job

  2. What is MATLAB? • MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. • Others include • Maple • Mathematica • MathCad

  3. MATLAB Excels at • Numerical calculations • Especially involving matrices • Graphics • MATLAB stands for Matrix Laboratory

  4. Why MATLAB • Easy to use • Versatile • Built in programming language • Not a general purpose language like C/C++ or Java • MATLAB was written in C Fluid Dynamics Electrical Engineering Biomedical Engineering

  5. Getting Started • Type in • matlab& • at the shell prompt in your terminal. • MATLAB opens to a default window configuration

  6. MATLAB uses a standard windows menu bar • To exit MATLAB use the close icon or from the menu: File->Exit MATLAB

  7. Command Window Enter commands at the prompt Current Directory MATLAB Windows Command History Workspace Window

  8. Command Window You can use the command window much like you’d use a calculator The standard order of operation rules apply

  9. Workspace Window Workspace Window

  10. Workspace Window Scalar Vector 2-D Matrix

  11. Document Window • If you double click on any variable in the workspace window MATLAB launches a document window containing the arrayeditor • You can edit variables in the array editor

  12. Document Window

  13. Figure Window • When Figures are created a new window opens • It’s extremely easy to create graphs in MATLAB The semicolon suppresses the output from each command

  14. Editing Window • This window allows you to type and save a series of commands without executing them • There are several ways to open an editing window • From the file menu • With the new file icon

  15. Open an editing window from the file menu or with the new file icon

  16. Save and Run Write your code in the editing window, then run it using the Save and Run icon

  17. Solving Problems with MATLAB

  18. Naming Variables • All names must start with a letter • They may contain letters, numbers and the underscore ( _ ) • Names are case sensitive • There are certain keywords you can’t use (iskeyword)

  19. The Basic Data Type in MATLAB: Matrices • Group of numbers arranged into rows and columns • Single Value (Scalar) • Matrix with one row and one column • Vector (One dimensional matrix) • One row or one column • Matrix (Two dimensional)

  20. Array Operations • Using MATLAB as a glorified calculator is OK, but its real strength is in matrix manipulations

  21. To create a row vector, enclose a list of values in brackets

  22. You may use either a space or a comma as a “delimiter” in a row vector

  23. Use a semicolon as a delimiter to create a new row

  24. Use a semicolon as a delimiter to create a new row

  25. Shortcuts • While a complicated matrix might have to be entered by hand, evenly spaced matrices can be entered much more readily. The command  • b= 1:5 • or the command • b = [1:5] • both return a row matrix 

  26. The default increment is 1, but if you want to use a different increment put it between the first and final values

  27. To calculate spacing between elements use linspace number of elements in the array initial value in the array final value in the array

  28. Calculations between scalars and arrays

  29. Calculations between arrays: addition and subtraction Addition between arrays is performed on corresponding elements Subtraction between arrays is performed on corresponding elements

  30. Multiplication between arrays is performed on corresponding elements if the .* operator is used MATLAB interprets * to mean matrix multiplication. The arrays a and b are not the correct size for matrix multiplication in this example

  31. Array Operations • Array multiplication .* • Array division ./ • Array exponentiation .^ In each case the size of the arrays must match

  32. Transpose • The transpose operator changes rows to columns or vice versa.

  33. The transpose operator makes it easy to create tables

  34. table =[degrees;radians]’ would have given the same result

  35. The transpose operator works on both one dimensional and two dimensional arrays

  36. Saving Your Work • If you save a MATLAB session, all that is saved are the values of the variables you have named

  37. Save either by using the file menu or... Save with a command in the command window MATLAB automatically saves to a .mat file

  38. Script M-files • If you want to save your work, you need to create an M-file • File->New->M-file • Type your commands in the edit window that opens • The file is saved into the current directory • It runs in the command window

  39. Comments • The % sign identifies comments • You need one on each line

More Related