MEEN210_L02_MATLAB basics
MEEN210_L02_MATLAB basics
Today’s Goals.
Command Window
Text editor window
Directory
Where you write code Workspace
space,
(History)
Files, etc.
(Where you
save code and
data)
Command window
Where you type commands and run code
Let’s Play – MATLAB
>> X=99;
>> x = 88;
Left to right
Mechanical Engineering – MEEN 210
Command Window
Command Window
>> a+b*c/d^e 3 + 5 * 7/9^11
ans =
3.0000
>> format long (page 27)
Use the up arrow to recall previous
commands –
>> a+b*c/d^e
ans =
3.000000001115323
Mathematical Operations
Order of Calculations
Order of Priority (page 32):
1. ( ) 2. ^
3. * 4. /
5. + or -
Another Problem in the Command Window
>> 5 + 8 * 9 – 7 / 3 * 2^3
Answer = 58.3333
How?
1st Step?
“^” first = = > 5 + 8 * 9 – 7 / 3 * 8
2nd Step?
* and / = = > 5 + 72 – 2.3333 * 8
Command Window
>> 5 + 8 * 9 – 7 / 3 * 2^3
2nd Step?
* and / = = > 5 + 72 – 2.3333 * 8
5 + 72 – 18.6667
3rd Step?
+ and - = = > 77 + (-18.6667)
Mechanical Engineering – MEEN 210
Original equation
>> 5 + 8 * 9 – 7 / 3 * 2^3
4th Step?
Answer = 58.3333
Mathematical Operations
Order of Calculations
>> x1=(45/5)*10 - 20*(-50)
Do in MATLAB
Mechanical Engineering – MEEN 210
Graphic Window
Plotting Data and lines or curves through
the Data:
Very Powerful Tool in Engineering – Plotting
Plotting in MATLAB
Make some vectors; x and y
>> plot(x, y)
Mechanical Engineering – MEEN 210
Mechanical Engineering – MEEN 210
>> hold on
Supported styles:
https://www.mathworks.com/help/matlab/cre
ating_plots/create-line-plot-with-
markers.html#bvcbmlz-1
Mechanical Engineering – MEEN 210
Mechanical Engineering – MEEN 210
Good practice:
• Labels and axes same font size as main document (or larger)
• Increase line width on plot lines and symbols
• Pay attention to white space. Don’t crowd axes.
• Each symbol and line should be a different color and or style (solid,
dashed, squares, triangles)
Mechanical Engineering – MEEN 210
Plotting in MATLAB
Make some vectors; x1 and y1
>> x1=[1 2 3 4 5 6]
>> y1=[.1 .2 .3 .4 1 1.5 1.7 1.9];
What happens?
Mechanical Engineering – MEEN 210
Vectors in MATLAB
>> xx = [
81
90
13
91
63
10
28
55
95
96
16 ]
Mechanical Engineering – MEEN 210
Vectors (continued)
>> yy = [
266
203
286
295
269
277
275
240
266
217
272]
Mechanical Engineering – MEEN 210
>> length(xx)
>> length(yy)
>> sum(xx)
>> sum(yy)
Mechanical Engineering – MEEN 210
Turn On
EXCEL®
Mechanical Engineering – MEEN 210
Type in
a
5
7
9
11
Mechanical Engineering – MEEN 210
Cells in EXCEL
Numbers
Operations
Mathematical Operations
Order of Calculations in EXCEL
Order of Priority:
1. ( ) 2. ^
3. * 4. /
5. + or -
Same as MATLAB
Mechanical Engineering – MEEN 210
EXCEL Plotting
Data in Columns
2 4
5 25
7 49
9 81
Mechanical Engineering – MEEN 210
Classwork Problems
Do in MATLAB Command Window and EXCEL
1. (9/11)/(33*(5*7)) =
2. 19/8 – (7/6) =
3. 2^(5 + (6/8)) =
4. (18 – (20/17)) =