School
York UniversityDepartment
Information TechnologyCourse Code
ITEC 2600Professor
Marshall WalkerStudy Guide
FinalThis preview shows pages 12. to view the full 8 pages of the document.
BASIC OPERATIONS:
OPERATION
SYMBOL
EXAMPLE
Addition
+
5 + 3
Subtraction
–
5 – 3
Multiplication
*
5 * 3
Right Division
/
5 / 3
Left Division
\
5 \ 3 = 3 / 5
Exponential
^
5 ^ 3 = 53 = 125
COMMAND
DESCRIPTION
EXAMPLE
format short
4 decimal digits
>> 290 / 7
ans =
41.4286
format long
>> 290 / 7
ans =
41.428571428571431
format bank
Two decimal digits
>> 290 / 7
ans =
41.43
COMMAND
DESCRIPTION
sqrt (x)
square root
nthroot(x , n)
Nth real root
exp (x)
ex
abs (x)
absolute value
log (x)
natural log (base e)
factorial (x)
x!
sin (x)
sine (x in radians)
cos (x)
cosine (x in radians)
tan (x)
tangent (x in radians)
sind (x)
sine (x in degrees)
cosd (x)
cosine (x in degrees)
tand (x)
tangent (x in degrees)
round (x)
Round to the nearest integer
A variable is a name that is assigned a numerical value:
o Can read the variable (get its value)
o Can write to the variable (set its value)
o Case sensitive: an underscore is placed in place of a space (e.g. speed_of_light or speedOfLight)
Keywords: pi (π), inf/Inf (infinity)
find more resources at oneclass.com
find more resources at oneclass.com
Only pages 12 are available for preview. Some parts have been intentionally blurred.
VECTORS AND MATRICES:
A matrix is used to store a set of values of the same type; every value is stored in an element.
o A matrix with m rows and n columns is called m x n; these are called dimensions. e.g. this is a 2x3 matrix
9
6
3
5
7
2
o The term array is used in MATLAB to refer generically to a matrix or a vector.
A vector is a special case of matrix in which one of the dimensions is 1:
o A row vector with n elements is 1 x n, e.g. 1 x 4
o A column vector with m elements is m x 1, e.g. 3 x 1
A scalar is an even more special case; it is 1 x 1, or in other words, just a single value.
Direct Method: put the values you want in square brackets, separated by either commas or spaces.
o >> v = [1 2 3 4]
v =
1 2 3 4
Colon operator: iterates through values in the form first : step : last. E.g. 4 : 1 : 1 creates [4 3 2 1]
The function linspace creates a linearly spaced vector; linspace(x,y,n) creates a vector with n values in the
inclusive range from x to y
o E.g. linspace(4,7,3) creates a vector with 3 values including the 4 and 7 so it returns [4 5.5 7]
Builtin functions:
o rand (n) creates an nxn matrix of random reals
o rand(n,m) creates an nxm matrix of random reals
o randi([range], n, m) creates an nxm matrix of random integers in a specified range
o min the minimum value
o max the maximum value
o sum the sum of the elements
o prod the product of the elements
length(vec) returns the # of elements in a vector
length(mat) returns the larger dimension (row or column) for a matrix
size returns the # of rows and columns for a vector or matrix
numel returns the total # of elements in a vector or matrix
CHAPTER 3: STRINGS
A string is an array of characters
Create a string by typing characters within single quotes
Elementwise operations on arrays:
Symbol
Description
Symbol
Description
.*
Multiplication
./
Right Division
.^
Exponentiation
.\
Left Division
Dot product [dot(a,b)]
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview
Unlock to view full version
Only pages 12 are available for preview. Some parts have been intentionally blurred.
WEEK 4: INPUT
The input function does two things: prompt the user and reads in a value.
o variablename = iputpropt strig
Conversion characters (fprintf)
%d integers
%f floats(real numbers)
%c single characters
%s strings
Formatting output:
\n newline character
\t tab character
\\ to print one slash
WEEK 5: 2D PLOTS
plot (x,y)
plot ,, lie specifier, PropertNae, PropertValue
o x is a vector
o y is a vector
o line specifiers – specifiers that define the type and color of the line and markers.
o PropertyName and PropertyValue – properties with values that can be used to specify the line width,
ad arkers size ad edge, ad fill colors.
Line Style
Specifier
Solid (default)

Dashed

Line Style
Specifier
Dotted
:
Dashdot
.
Line Color
Specifier
red
r
green
g
blue
b
cyan
c
Line Color
Specifier
magenta
m
yellow
y
black
k
white
W
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview
Unlock to view full version