matlab week 1.2 Flashcards
(31 cards)
vectors
one dimensional collection of variables written between brackets []
[1 2 3 4 5 ]
row vector
[1; 2; 3; 4; 5]
column vector
size(x)
returns dimensions of row (two values, n by m)
length(x)
returns number of elements in a vector (one value)
linspace
generates row vector of n points between and including two points
y = linspace(a, b, n)
what does each letter represent?
y is the created row vector
a is the starting number, included
b is the end number, included (if it fits in increment)
n is the number of points generated
linspace(1,5)
returns 1 by 100 vector between 1 and 5
default ‘n’ if not specified by linspace function
100
linspace(1, 5, 1)
5
you generated one number between 1 and 5 so it took a stepsize of 5
t = [1 2 3]
y = log(t)
what is y?
y = [ log(1), log(2), log(3) ]
element wise operations
use dot
.* ./ .^
transpose
converts column vector into a row vector and vice versa (‘)
a = [ 1 2 3]
a’
a =
1
2
3
b = [ 1, 2, 3, 4 + i]
b’
b =
1
2
3
4 - i
b = [ 1 2 3 4+i]
b.’
b =
1
2
3
4 + i
zeros and ones function
zeros -> creates n by m matrix filled with 0s
ones -> creates n by m matrix filled with 1s
ones(3)
1 1 1
1 1 1
1 1 1
zeros(2, 3)
0 0 0
0 0 0
rand function
generates matrix with random numbers between 0 and 1
rand(3)
random 0-1 matrix of 3 by 3 dims
randi(10,1,5)
randomly generates 10 integer numbers (whole numbers) between 1 and 5
writing mathmatical equations in matlab
use the roots function with value as coefficient and index as the root
6e^-10t
6 * exp(-10 * t)