Professional Documents
Culture Documents
By
Mueen M. Al-Rubye
Assist Lecturer
2020
Mueen M. Al-Rubaye Engineering Technical College - Najaf
Introduction
1
Mueen M. Al-Rubaye Engineering Technical College - Najaf
MATLAB Environment
Command History
Figure (1) the desktop of MATLAB
Window
2
Mueen M. Al-Rubaye Engineering Technical College - Najaf
When you get into MATLAB, it contains these main basic windows:
• Command Window: This is the main area where commands can be entered at
the command line. It is indicated by the command prompt (>>). As shown in
Figure (1).
• Workspace Window: It shows all the variables created and/or imported from
files. As shown in Figure (1):
• Command History Window: This panel shows or rerun commands that are
entered at the command line. As shown in Figure (1):
• Current Folder Window: This panel allows you to access the project folders and
files. As shown in Figure (1):
3
Mueen M. Al-Rubaye Engineering Technical College - Najaf
2.1. Variables
• A variable represents any types of data, it usually represents a scalar, a vector,
a string, or a matrix. In order to store values, either in an M-file or the Command
Window, variables are used.
variable = expression
For example:
>> x = 4
X =
4
• This variable can then be used on the right-hand side of an equation such as
>> f = 3*x^6 - 17*x^3 + 79
• Overwritten: if you put another value to the variable x (like x=5) it takes the
new value x=5 not 4
• There are some variables we are not preferable to use such as:
pi = 𝜋 3.14
i, j = √−1
inf infinity
∞
nan not a number (e.g. the result of 0/0)
ans default variable for results
4
Mueen M. Al-Rubaye Engineering Technical College - Najaf
• Variables can also be deleted by using clear. For example, to delete x type
>> clear x
Variables: Case Sensitive which means variable X capital letter is not the same
x small letter.
must start with a letter, and can then be followed by any number of
letters, numbers, and/or underscores (so z_0 is allowed).
, Separates multiple statements on the same line. The results appear
on the screen.
; The result is not printed on the screen. This can
also separate multiple statements on the same line.
% Begin a comment.
5
Mueen M. Al-Rubaye Engineering Technical College - Najaf
Command Purpose
clc Clears command window.
Clear Removes variables from memory.
Quit Stops MATLAB.
Lookfor Searches help entries for a keyword.
Who Lists current variables.
Whos Lists current variables (long display).
Operator Description
() parentheses
^ exponentiation
*, /, \ all multiplication and division
+, - addition and subtraction
For example:
❶ ❷ ❶ ❷
❶ ❶
❷ ❷ ❸ ❸
❹ ❹
6
Mueen M. Al-Rubaye Engineering Technical College - Najaf
Examples: Answer:
Write the following by using MATLAB: 6* 35^ (1/4) + 14^.35
/
6 ,350 1 + 143.56 Ans=
17.1123
Boolean variable = variable with true / false value, 1 means true and 0 means false.
For example:
1 < 3 3 < 2 3 < 3
ans= ans= ans=
1 0 0
1 <= 3 x=12; x ~= 13
ans= x == 13 ans=
1 ans= 1
0
(x==12) | (x<3) (x==12) | (x<3)
ans= ans=
1 0
7
Mueen M. Al-Rubaye Engineering Technical College - Najaf
Function Meaning
ceil Round to the nearest integer toward ∞ (e.g.: 3.6 becomes 4)
fix(x) Round to the nearest integer toward zero (e.g.: 3.6 becomes 3)
floor(x) Round to the nearest integer toward -∞ (e.g.: -3.6 becomes -4)
sign(x) Return sign of the number (e.g.: plus, minus, or zero)
mod(x) Return the real part of division x/y (e.g.: result =3.5 return 3)
Function Meaning
sqrt(x) Square root, √x
exp(x) Exponential, 𝑒 :
log(x) Natural logarithm
log10(x) Common (base 10) logarithm
sin(x) Sine
abc(x) Absolute Value |x|
asin(x) Inverse sine
cos(x) Cosine
acos(x) Inverse cosine
tan(x) Tangent
atan(x) Inverse tan
For example: the value of the expression 𝒚 = 𝒆=𝒂 𝐬𝐢𝐧(𝒙) + 𝟏𝟎G𝒚 for a = 5, x=2
and y=8.
>> a=5; x=2; y=8;
>> y=exp(-a)*sin(x)+10*sqrt(y)
Y=
28.2904
8
Mueen M. Al-Rubaye Engineering Technical College - Najaf
𝑥
𝑧 = 𝑡𝑎𝑛=_ ( ) 𝑧 = atan (𝑥 /𝑦)
𝑦
|𝑦 − √𝑥|
𝑧= 𝑧 = 𝑎𝑏𝑠(𝑦 − 𝑠𝑞𝑟𝑡(𝑥))/(𝑎 − 𝑏)
(𝑎 − 𝑏)
Reference:
Overman, E. (2016). A MATLAB Tutorial. Department of Mathematics. The Ohio State University,
Columbus, 180.
MATLAB, M. (2012). The language of technical computing. The MathWorks, Inc. http://www.mathworks.com.