Lecture Notes 5
Lecture Notes 5
See the sample programs for examples of most of the commands used
in making the plots.
[mx, idx] = max(v)...
’MarkerIndices’
(please submit .pdf or image of graph rather than .fig)
We can also take advantage of the recursive definition, and define our
function recursively:
>> fiboRec(4)
Computing f(4)
Computing f(2)
Computing f(0)
Computing f(1)
Computing f(3)
Computing f(1)
Computing f(2)
Computing f(0)
Computing f(1)
ans =
3
>> ones(2, 3)
1 1 1
1 1 1
>> ones(2)
1 1
1 1
Try also:
zeros(m,n)
rand(m,n)
randn(m,n)
randi(k,m,n)
What happens if you enter only m and leave out n?
>> eye(2)
1 0
0 1
>> v = [3,5]; diag(v)
3 0
0 5
>> diag(v,-1) + 2*eye(3)
2 0 0
3 2 0
0 5 2
As with vectors, we have lots of ways to access and manipulate the entries
of matrices. Try out the following commands:
>> A = reshape(1:12,3,4)
>> size(A) % also size(A,1) and size(A,2)
>> A’
>> fliplr(A) % also flipud(A)
>> A(2,3)
>> A(:,[2,4])
>> p = randperm(3); q = randperm(4); A(p,q)
>> reshape(A,2,6)
>> A(5,5) = 1
>> x = inv(A)*b
>> x = A\b
where
j
Y
ωj (x) = (x − xk ).
k=0
(n = 1) (k = 0) (k = 1)
(n = 0) (k = 0)
m 7→ (m = 0) · ·
(m = 0) δn,k m
(m = 1) · δn,k
n k =0:n
m = 0 : min(n, M) m
δn,k