Matlab Leason One
Matlab Leason One
Operator Purpose
Plus; addition operator.
+
Minus; subtraction operator.
-
Scalar and matrix multiplication operator.
*
Array multiplication operator.
.*
Scalar and matrix exponentiation operator.
^
Array exponentiation operator.
.^
Left-division operator.
\
Right-division operator.
/
Commonly used Operators and Special Characters
Operator Purpose
./ Array right-division operator.
. Decimal point.
= Assignment operator.
Special Variables and Constants
Name Meaning
ans Most recent answer.
Inf Infinity.
pi The number π
Naming Variables
• Variable names consist of a letter followed
by any number of letters, digits or
underscore.
• MATLAB is case-sensitive.
• Variable names can be of any length,
however, MATLAB uses only first N
characters, where N is given by the
function namelengthmax.
VARIABLES
• In MATLAB environment, every variable is an array or
matrix.
• You can assign variables in a simple way. For
example
Example 1.
• x = 7 % defining x and initializing it with a value
• MATLAB will execute the above statement and return
the following result:
• x=
3
• It creates a 1-by-1 matrix named x and stores the
value 3 in its element.
• Example 2.
• x = sqrt(16) % defining x and initializing it with an
expression
• MATLAB will execute the above statement and return
the following result:
• x=4
• Once a variable is entered into the system, you can
refer to it later.
• Variables must have values before they are used.
• When an expression returns a result that is not
assigned to any variable, the system assigns it to a
variable named ans, which can be used later.
• For example,
sqrt(78)
• MATLAB will execute the above statement and return
the following result:
ans =
8.8318
• You can use this variable ans:
ans * 56
Result
ans =
494.5786
The who and whos command