lecture 20: choosing the right tool for the job. what is matlab? matlab is one of a number of...
TRANSCRIPT
![Page 1: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/1.jpg)
Lecture 20: Choosing the Right Tool for the Job
![Page 2: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/2.jpg)
What is MATLAB?• MATLAB is one of a number of
commercially available, sophisticated mathematical computation tools.
• Others include• Maple• Mathematica• MathCad
![Page 3: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/3.jpg)
MATLAB Excels at
• Numerical calculations• Especially involving matrices
• Graphics• MATLAB stands for
Matrix Laboratory
![Page 4: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/4.jpg)
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
QuickTime™ and a decompressor
are needed to see this picture.
Electrical Engineering Biomedical Engineering Fluid Dynamics
![Page 5: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/5.jpg)
Getting Started
• Type in
matlab&
at the shell prompt in your terminal.• MATLAB opens to a default window configuration
![Page 6: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/6.jpg)
MATLAB uses a standard windows menu barTo exit MATLAB use the close icon or from the menu: File->Exit MATLAB
![Page 7: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/7.jpg)
Command Window
Enter commands at the promptCurrent Directory
MATLAB Windows
Command HistoryWorkspace Window
![Page 8: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/8.jpg)
You can use the command window much like you’d use a calculator
The standard order of operation rules apply
Command Window
![Page 9: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/9.jpg)
Workspace Window
Workspace Window
![Page 10: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/10.jpg)
Workspace Window
Scalar
Vector
2-D Matrix
![Page 11: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/11.jpg)
Document Window
If you double click on any variable in the workspace window MATLAB launches a document window containing the array editorYou can edit variables in the array editor
![Page 12: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/12.jpg)
Document Window
![Page 13: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/13.jpg)
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
![Page 14: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/14.jpg)
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
![Page 15: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/15.jpg)
Open an editing window from the file menu or with the new file icon
![Page 16: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/16.jpg)
Save and Run
Write your code in the editing window, then run it using the Save and Run icon
![Page 17: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/17.jpg)
Solving Problems with MATLAB
![Page 18: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/18.jpg)
Naming Variables
All names must start with a letterThey may contain letters, numbers and the underscore ( _ )Names are case sensitiveThere are certain keywords you can’t use (iskeyword)
![Page 19: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/19.jpg)
The Basic Data Type in MATLAB: Matrices
Group of numbers arranged into rows and columnsSingle Value (Scalar) Matrix with one row and one column
Vector (One dimensional matrix) One row or one column
Matrix (Two dimensional)
![Page 20: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/20.jpg)
Array OperationsUsing MATLAB as a glorified calculator is OK, but its real strength is in matrix manipulations
![Page 21: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/21.jpg)
To create a row vector, enclose a list of values in brackets
![Page 22: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/22.jpg)
You may use either a space or a comma as a “delimiter” in a row vector
![Page 23: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/23.jpg)
Use a semicolon as a delimiter to create a new row
![Page 24: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/24.jpg)
Use a semicolon as a delimiter to create a new row
![Page 25: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/25.jpg)
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
![Page 26: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/26.jpg)
The default increment is 1, but if you want to use a different increment put it between the first and final values
![Page 27: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/27.jpg)
To calculate spacing between elements use linspace
initial value in the array
final value in the array
number of elements in the array
![Page 28: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/28.jpg)
Calculations between scalars and arrays
![Page 29: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/29.jpg)
Calculations between arrays: addition and subtraction
Addition between arrays is performed on corresponding elements
Subtraction between arrays is performed on corresponding elements
![Page 30: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/30.jpg)
MATLAB interprets * to mean matrix multiplication. The arrays a and b are not the correct size for matrix multiplication in this example
Multiplication between arrays is performed on corresponding elements if the .* operator is used
![Page 31: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/31.jpg)
Array Operations
Array multiplication .*Array division ./Array exponentiation .^
In each case the size of the arrays must match
![Page 32: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/32.jpg)
Transpose
The transpose operator changes rows to columns or vice versa.
![Page 33: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/33.jpg)
The transpose operator makes it easy to create tables
![Page 34: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/34.jpg)
table =[degrees;radians]’ would have given the same result
![Page 35: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/35.jpg)
The transpose operator works on both one dimensional and two dimensional arrays
![Page 36: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/36.jpg)
Saving Your Work• If you save a MATLAB session, all that is
saved are the values of the variables you have named
![Page 37: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/37.jpg)
Save either by using the file menu or...
Save with a command in the command window
MATLAB automatically saves to a .mat file
![Page 38: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/38.jpg)
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
![Page 39: Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation](https://reader035.vdocuments.mx/reader035/viewer/2022062804/5697bf981a28abf838c914ae/html5/thumbnails/39.jpg)
Comments
• The % sign identifies comments
• You need one on each line