Homework Assignment 0 - SOLUTIONS CSCI 510/EENG 510

advertisement
CSCI 510/EENG 510
Image and Multidimensional Signal Processing
Homework Assignment 0 - SOLUTIONS
This assignment is a review of some pre-requisite topics. It is not necessary to turn it in, although you should do
these problems to make sure you understand the concepts.
The first four problems are a review of some mathematical concepts. You should be able to do
these problems by hand, but it is ok to check with a computer.
 4 − 2
 .
1. Consider the matrix A = 
1 1 
a) Find the transpose of A
b) Find the determinant of A
c) Find the trace of A
d) Find the inverse of A.
e) Which of the following vectors is an eigenvector of A?
x = (-1 2)T
x = (2 1)T
x = (0 1)T
x = (1 0)T
Solution:
 4 1

a) A T = 
 − 2 1
b) |A| = det(A) = (4)(1) – (-2)(1) = 6.
c) tr(A) = 4+1 = 5.
 1/ 6 1/ 3 

d) You can use the “cofactor” method. A −1 = 
 − 1 / 6 2 / 3
e) The definition of an eigenvector is Ax = λx, where λ is the eigenvalue for that
eigenvector. Trying each of the possibilities, we see that A (2 1)T = (6 3) T = 3(2 1)T .
So (2 1)T is an eigenvector, and λ = 3 is the corresponding eigenvalue.
2. Consider the vectors x = (1 2 3)T and y = (-1 2 -3)T.
a) Compute the inner (dot) product x∙y.
b) Compute the vector (cross) product x × y .
Solution:
a) -6
b) (-12 0 4)T
3.
Consider the 8-bit binary number B = 11000001.
a) Find the decimal value of B if it represents an unsigned binary number
b) Find the decimal value of B if it represents a two’s complement binary number.
Solution:
a) 1*2^7 + 1*2^6 + 0 + 0 + 0 + 0 + 0 + 1 = 193.
b) -1*2^7 + 1*2^6 + 0 + 0 + 0 + 0 + 0 + 1 = -63.
1
CSCI 510/EENG 510
Image and Multidimensional Signal Processing
4. The faces of a 10-sided die are numbered 0 through 9.
a) What is the probability that the value of the roll is a prime number?
b) What is the expected value of the roll?
c) If the die is rolled twice, what is the probability that the same number is
obtained both times?
Solution:
a) The possible prime numbers in the range 0..9 are 2, 3, 5, and 7. There are four
outcomes (out of 10), so the probability is 0.4.
10
b) The expected value is xavg = E ( x ) = ∑ xi p( xi ) = (0)(.1)+(1)(.1)+(2)(.1)+...+(9)(.1) =
i =1
4.5.
c) The probability that any particular number (such as a “1”) is rolled twice is
(0.1)(0.1)=0.01. There are 10 possible outcomes like this, so the total probability is
(10)(0.01) = 0.1.
5. Matlab exercises.
a) Create a matrix A, any size and shape you want, and fill it with arbitrary values.
Compute AAT and ATA. The results should be square, symmetric matrices.
b) Write a Matlab program to produce the first 30 Fibonacci numbers.
Solution:
a)
>> A = rand(3,5)
A=
0.0357 0.6787
0.8491 0.7577
0.9340 0.7431
>> A*A'
ans =
1.1164 0.8287
0.8287 1.7353
0.8384 1.5572
>> A'*A
ans =
1.5946 1.3617
1.3617 1.5871
0.7305 0.8901
0.3109 0.7091
0.8532 0.7169
0.3922 0.7060 0.0462
0.6555 0.0318 0.0971
0.1712 0.2769 0.8235
0.8384
1.5572
2.2087
0.7305
0.8901
0.6128
0.3452
0.2227
0.3109
0.7091
0.3452
0.5762
0.2637
0.8532
0.7169
0.2227
0.2637
0.6896
b)
% Generate Fibonacci numbers.
% Fibonacci numbers are defined as the sequence F(n) = F(n-1) + F(n-2),
% starting with the numbers F(0)=0 and F(1)=1.
% Good idea to have these two instructions at the beginning of any program.
clear all
% Clear workspace of any old variables
2
CSCI 510/EENG 510
close all
Image and Multidimensional Signal Processing
% Close all open figures
n1 = 0;
fprintf('1 %d\n', n1); % To print to console, use "fprintf" or "disp"
n2 = 1;
fprintf('2 %d\n', n2);
for i=3:30
temp = n1 + n2;
fprintf('%d %d\n', i, temp);
n1 = n2;
n2 = temp;
end
Output is:
10
21
31
42
53
65
78
8 13
9 21
10 34
11 55
12 89
13 144
14 233
15 377
16 610
17 987
18 1597
19 2584
20 4181
21 6765
22 10946
23 17711
24 28657
25 46368
26 75025
27 121393
28 196418
29 317811
30 514229
3
Download