Shared Flashcard Set

Details

MATLAB: A practical introduction Ch.1
variables, expressions, assignment statements, characters, encoding, vectors, matrices
88
Mathematics
Undergraduate 3
10/12/2011

Additional Mathematics Flashcards

 


 

Cards

Term
script file
Definition
Term
m-file
Definition
Term
prompt
Definition
Term
command window
Definition
Term
workspace
Definition
Term
assignment statement
Definition
variablename = expression
Term
assignment operator
Definition

=

does not mean equality

Term
;
Definition
suppresses output
Term
default variable
Definition
ans
Term
initializing (a variable)
Definition
 Putting the first or initial value in a variable
Term
incrementing
Definition

adding to a variable

ex. mynum= mynum+1 increments by 1

Term
decrementing
Definition

subtracting from a variable

ex. num = num-1 decrements by 1

Term
identifier names
Definition

ex. variable names

rules:

must begin with letter

can have letters, digits, and _ (underscore)

no spaces

limit to length (namelengthmax to find)

case-sensitive (Num_1 =/= num_1)

cannot be a reserved word

*should* not be name of built-in function

Term
who
Definition

shows variables that have been defined in this Command Window (only shows variable names)

 

>>who

Your variables are:

ans mynum variablename

Term
whos
Definition

shows more information on variables defined in Command Window

 

shows name, size, bytes, class, attributes

Term
clear
Definition
clears out all variables so they no longer exist
Term
clear variablename
Definition
clears out the variable variablename
Term
expression
Definition
a combination of values, variables that have already been created, operators, built-in functions, and parentheses that can be computed by Matlab and output a value
Term
default format
Definition
displays 4 decimal places
Term
format short
Definition

default

 

4 decimal places

Term
format long
Definition
shows 15 decimal places
Term
format loose
Definition

default

 

ans=

 

     128

Term
format compact
Definition

ans=

   128

Term
ellipsis
Definition

...

 

used for long expressions that continue on the next line

ex.

3 + 5 - 62 + 4 - 5 ...

+ 22 - 1

 

ans=

16

Term
unary operator
Definition

operates on a single value

ex.

"-"

-7

negative

Term
operand
Definition

value that an operator operates on

ex.

7 and 2 in

7*2

Term
binary operator
Definition

operates on 2 values

ex.

+

-

*

/ divided by

\ divided into

^ exponentiation

Term
operator precedence
Definition

priority in order of operations

 parenthesis can change precedence

highest->lowest precedence:

()

^

- (negation)

*, /, \

+, -

Term
associativity
Definition
in the same precedence level, operations are performed from left to right
Term
nested parentheses
Definition

inner parentheses evaluated first

ex.

3*((4^2)+7)

Term
help elfun
Definition

lists and describes built-in elementary functions

 

broken into trigonometric (for which the default is radians), exponential, complex, and rounding
and remainder functions

Term
help ops
Definition
lists and describes operators
Term
argument, call, return
Definition

value that function is applied to

ex.

abs(-4)

calls the function abs

returns 4

Term
fix
Definition
Term
floor
Definition
Term
ciel
Definition
Term
round
Definition
Term
rem
Definition
Term
sign
Definition

returns either 1 or -1 or 0

indicates positive, negative or 0

Term
constants
Definition

matlab stores

 

pi   3.14...

i   sqrt(1)

j   sqrt(1)

inf   infinity

NaN   (0/0)

 

Term
e
Definition

e is not stored as constant

 

e=exp(1)

=2.7183

Term
type single
Definition
for a variable or expression
Term
type double
Definition

default

for "double precision"

larger numbers than single

Term
integer types
Definition

int8 - 8 bits to store the integer and its sign (-128 to 127)

int16

int32

int64

 

to find the range for each, use intmin('int32') and intmax('int32')

 

using the smallest type saves space

if you go beyond the range of a type, it will use its max instead

int8(200) = 127

Term
char type
Definition

stores single characters (eg 'x')

or

strings, sequences of characters (eg 'cat')

 

enclosed in ' '

Term
type logical
Definition
stores true/false values
Term
type casting
Definition

changing a value to a different type

 

use name of type changed to as fuction

ex.

change num from double to int32

num=int32(num)

 

 

Term
random numbers
Definition

pseudo-random, start with seed that is predetermined or assigned by a clock in the computer

 

the seed is the same every time Matlab is opened, unless that state is changed

rand('state',sum(100*clock))

Term
rand
Definition

generates a random number between 0 and 1

with 4 decimal places

 

>>rand

ans=

.2311

 

rand*n will generate a random number from 0 to n

rand*7

 

to generate a random number from low to high

low=4;

high=5;

rand*(high-low)+low

Term
rantint
Definition

>> randint(1,1,n)
generates one random integer in the range from 0 to n-1

(default type double)

 

>> randint(1,1,[1,20])

generates a random integer between 1 and 20

Term
character set
Definition

 includes all letters of the alphabet, digits, punctuation marks, and more; all the keys on a keyboard

 

given integer values

use ' ' for characters

Term
ASCII
Definition

 American Standard Code for Information Interchange

 

128 characters

integer values from 0 to 127

Term
char
Definition

converts from number type to char type

ex.

char(97)

ans=

a

Term
string
Definition

sequence of characters

ex.

'abcd'

 

double('abcd')

ans=

97  98  99  100

 

char('abcd'+1)

ans=

bcde

Term
matrix
Definition

dimensions r x c (r by c)

2d array

mat=[1 2 3; 4 5 6]

or

mat=[1:3; 4:6]

 

rand(r) creates a rxr matrix of random values between  0 and 1

rand(r,c) creates a r x c matrix of random numbers between 0 and 1

>> randint(2,4,[10,30]) creates a 2x4 matrix with random values in [10, 30]

zeroes(r,c) creates an r x c matrix of zeroes

Term
vector
Definition

1xn or nx1

row or column vector

row: v=[1 2 3 4] or v=[1,2,3,4] or v=1:5

 column: v' or [1;2;3;4]

subset of matrix

 

one dimensional array

Term
scalar
Definition

1x1

subset of matrix

Term
elements
Definition
values stored in matricies
Term
MATLAB
Definition
"matrix laboratory"
Term
step value
Definition

first:step:last

nv=1:2:9

nv=

1    3    5    7    9

 

nv=1:-2:9

9    7    5    3    1

Term
colon operator
Definition

:

 

1:5

1 2 3 4 5

x:y

iterates through x to y

regularly spaced

Term
linspace
Definition

linspace(x,y,n) creates a vector with n values in the inclusive range [x,y], evenly (linearly) spaced

 

linspace(3,15,5)

3    6    9    12    15

Term
concatenating vectors
Definition

combine two vectors

vec1 = 1:2:9=[1    3    5    7    9]

vec2 = linspace(3,15,5)=[3    6    9    12    15]

newvec = [vec1 vec2]

newvec=

1    3    5    7    9    3    6    9    12    15

Term
index
Definition

aka subscript

element number

indexes start at 1 in MATLAB

vec=[3   12    7    1]

 

vec(2)=12

Term
subset of a vector
Definition

also a vector

vec=[3   12   7   1]

 

vec(2:4)= [12   7   1]

 

uses colon operator :

Term
index vector
Definition

used to get specified elements of another vector

index=[1   3    4]

vec=[ 2   6    7    3    9]

 

vec(index)=vec([1   3   4])=

[2   7   3]

 

 

Term
extend a vector
Definition

vec=[ 2   6    7    3    9]

 

assign vec(7)=12

vec=

[ 2   6    7    3    9    0    12]

 

inserts 0 for unassigned elements

Term
matrix elements
Definition

mat(2,3) calls the element in the 2nd row and 3rd column

mat =
2    3    4
3    4    5

>> mat(1:2,2:3) 1st and 2nd row, 2nd and 3rd column
ans =
3    4
4    5

: means all rows or all columns

mat(:,:)=mat

mat(2,:) - 2nd row, all columns

mat(:,3) - all rows, 3rd column

 

Term
linear indexing
Definition

when single index is used, unwinds by columns

ex.

mat =
2    3    4
3    4    5

 

mat(4)= 4

Term
replace a row/column
Definition

replace 2nd row

mat(2,:)=5:7

 

replace 3rd column

mat(:,3)=[3 4]'

 

must have correct number of elements!

Term
extend a matrix
Definition

mat(4,:)=2:2:8

 

mat =
2    11    4    9
5     6    7    2
0     0    0    0
2     4    6    8

 

adds 0's to unassigned elements

Term
length
Definition
 will return either the number of rows or the number of columns, whichever is largest
Term
size
Definition

gives dimensions of an array

vec=[-2 1 0 1]

 

size(vec)=

1 4

 

1x4

r x c

Term
numel
Definition
returns number of elements in an array
Term
end
Definition

refers to the last column or row

 

mat(end, 1) calls the element in the last row, first column

 

Term
reshape
Definition

changes the dimensions of a matrix

 

iterates through the matrix columnwise

Term
fliplr
Definition

flips matrix from left to right

 

first column becomes last column etc

Term
flipud
Definition

flips up to down

 

first row becomes last row etc

Term
rot90
Definition

rotates the matrix clockwise 90 degrees

 

top-right corner becomes top-left corner

Term
repmat
Definition

repmat(mat,m,n)

 

creates a larger matrix which consists of an m x n matrix copies of mat

Term
empty vector
Definition

[ ]

 

can be used to delete elements or subsets from vectors

 

vec=1:5

vec(3)=[]

vec=

1  2  4  5

Term
element by element
Definition
default for abs
Term
\
Definition

Confusing the two division operators / and \

 

Supporting users have an ad free experience!