Starting from:
$30

$24

Lab Session 1 Solution

MA-423 : Matrix Computations Lab R. Alam







The purpose of this exercise is to illustrate anomaly in automatic computation. On my computer, Matlab produces





4


1) 3






2:2204 10 16


(






1
=


3


5
(1 + exp(
50))
1


=
NaN










(1 + exp(
50))
1






log(exp(750))
=
Inf










100

























Try on your machine. Can you explain the reason behind these anomalies?




Let A be a random matrix generated by rand(8). Find the maximum values (a) in each column, (b) in each row, and (c) overall. Also use find to find the row and column indices of all elements that are larger than 0:25:



A magic square is an n-by-n matrix in which each integer 1; 2; : : : ; n2 appears once and for which all the row, column, and diagonal sums are identical. MATLAB has a command magic that returns magic squares. Check its output for a few values of n and use MATLAB to verify the summation property. (The antidiagonal sum will be the trickiest. Look for help on how to “flip” a matrix.)



3. Consider the magic square A = magic(n) for n = 3, 4, or 5. What does




p = randperm(n); q = randperm(n); A = A(p,q);




do to




sum(A), sum(A’)’, sum(diag(A)), sum(diag(flipud(A))), rank(A)




The magic square A = magic(4) is singular. What do




null(A), null(A,’r’), null(sym(A)), and rref(A)




tell you about linear dependence of columns of A?




Are the following true or false? Assume A is a generic n-by-n matrix.



(a) A^ (-1) equals 1/A (b) A.^ (-1) equals 1./A




Suppose p is a row vector of polynomial coefficients. What does this line do?



(length(p)-1:-1:0) .* p




6. (a) Look up diag in the online help and use it (more than once) to build the 16-by-16 matrix














0


0


0
1
3


212 12 1


0
0
0


6
0




2


1




0
7


6
.1
.
.
.0
.
7


.




.


6
..
. .


. .


. .
. .
. .
..
7
D =
6




7


6


















7


6
0
0


0


1
2
1
0
7


6
0






0
1
2 1
7


6
















7


4














5


6 1
0
0




0
1
27
1
... ... ...







Now read about toeplitz and use it to build D:



Use toeplitz and whatever else you need to build





1
2
3


8




2
1






2


0
1
2
7




6










7


6
1














2
. .


.
3


6
.
60
0
. . .
1
2
7
and
1
6
..
..
. . .
..
7
6
..












6














7
60
0


0
1
7


6


1
6








7


6


8
4










5


4

























1


1
















2


1




3




1






2


1


.
















. .
1
6


1




1














7


2

















3
8

1 7

7 7

. 7

. 7

. 7 7

1 5

2

1
The second case looks best in format rat.




(a) Suppose A is a matrix whose entries are all positive numbers. Write one line ex-pression that will multiply each column of A by a scalar so that, in the resulting matrix, every column sums to 1:



Try this more difficult variation: Suppose that A may have zero entries, and leave a column of A that sums to zero unchanged.



A random Fibonacci sequence is generated by choosing x1 and x2 and setting xn+1 :=
xn xn 1; n 2: Here + and must have equal probability of being chosen. It is known that, with probability 1; for large n the quantity jxnj is of order cn; that is, jxn j = O(cn); where c := 1:13198824::: Your task is to test this assertion. Try the following script.




clear



rand(’state’, 1000)



x = [1, 2];



for n=2:999, x(n+1) = x(n)+sign( rand-0.5)*x(n-1); end



semilogy (1:1000, abs(x))



c =1.13198824;



hold on



semilogy(1:1000, c.^ [1:1000])



hold off




Try to understand what the above script does and why it does so. Use matlab command help to understand an in-built function/command whenever necessary.




*** End ***
































More products