computation tools Others include Maple Mathematica MathCad MATLAB Excels at Numerical calculations Especially involving matrices Graphics MATLAB stands for Mat rix Lab oratory Why MATLAB ID: 783596
Download The PPT/PDF document "What is MATLAB? MATLAB is one of a numbe..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
What is MATLAB?
MATLAB is one of a number of commercially available, sophisticated mathematical
computation
tools
.
Others include
Maple
Mathematica
MathCad
Slide2MATLAB Excels at
Numerical calculations
Especially involving matrices
GraphicsMATLAB stands for Matrix Laboratory
Slide3Why MATLAB
Easy to use
Versatile
Built in programming languageNot a general purpose language like C/C++ or JavaMATLAB was written in C
Medical imaging
Fluid Dynamics
Slide4Getting Started
Type in
matlab at the shell prompt in your terminal.MATLAB opens to a default window configuration
Slide5MATLAB uses a standard windows menu bar
To exit MATLAB use the close icon or from the menu: File->Exit MATLAB
Slide6Command Window
Enter commands at the prompt
Current Directory
MATLAB Windows
Command History
Workspace Window
Slide7You can use the command window much like you’d use a calculator
The standard order of operation rules apply
Command Window
Slide8Workspace Window
Workspace Window
Slide9Workspace Window
Scalar
Vector
2-D Matrix
Slide10Document 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
Slide11Document Window
Slide12Figure Window
When Figures are created a new window opens
It’s extremely easy to create graphs in
MATLABTry plotting
The semicolon suppresses the output from each command
Slide13Editing 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 menuWith the new file icon
Slide14Open an editing window from the file menu or with the new file icon
Slide15Save and Run
Write your code in the editing window, then run it using the Save and Run icon
Slide16Solving Problems with MATLAB
Slide17Naming Variables
All names must start with a letter
They may contain letters, numbers and the underscore ( _ )
Names are case sensitiveThere are certain keywords you can’t use (
iskeyword)
Slide18The Basic Data Type in MATLAB: Matrices
Group of numbers arranged into rows and columns
Single Value (Scalar)
Matrix with one row and one columnVector (One dimensional matrix)
One row or one column
Matrix (Two dimensional)
Slide19Array Operations
Using MATLAB as a glorified calculator is OK, but its real strength is in matrix manipulations
Slide20To create a row vector, enclose a list of values in brackets
Slide21You may use either a space or a comma as a “delimiter” in a row vector
Slide22Use a semicolon as a delimiter to create a
new
row
Slide23Use a semicolon as a delimiter to create a
new
row
Slide24Shortcuts
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
Slide25The default increment is 1, but if you want to use a different increment put it between the first and final values
Slide26To calculate spacing between elements use
linspace
initial value in the array
final value in the array
number of elements in the array
Slide27Calculations between scalars and arrays
Slide28Calculations between arrays: addition and subtraction
Addition between arrays is performed on corresponding elements
Subtraction between arrays is performed on corresponding elements
Slide29MATLAB 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
Slide30Array Operations
Array multiplication .*
Array division ./
Array exponentiation .^
In each case the size of the arrays must match
Slide31Transpose
The transpose operator changes rows to columns or vice versa.
Slide32The transpose operator makes it easy to create tables
Slide33table =[degrees;radians]’
would have given the same result
Slide34The transpose operator works on both one dimensional and two dimensional arrays
Slide35Saving Your Work
If you save a MATLAB session, all that is saved are the values of the variables you have named
Slide36Save either by using the file menu or...
Save with a command in the
command window
MATLAB automatically saves to a .mat file
Slide37Script M-files
If you want to save your
work
, you need to create an M-fileFile->New->M-fileType your commands in the edit window that opensThe file is saved into the current directoryIt runs in the command window
Slide38Comments
The % sign identifies comments
You need one on each line
Slide39Create a .m file that tabulates and plots the aerodynamic drag on a sphere of radius (r) of 5m as a function of velocity(V) (with V going from 0 to 100m/s). Assume the drag
coeficient
is 1.
The drag on a sphere is given by:Drag = Cd*0.5*air_density*V2*π
r2
Cd - drag coeficient
Air_density
= 1x10^-6
P
roblem we can do together:
Slide40Drag problem continued
:
Cd = 1;
V = [0:1:100];r=5;air_density=1e-6;
drag = Cd*air_density
*(V.^2)*pi*r^2;table = [
V',drag
']
plot (
V,drag
)
Do the results make sense?