Matlab4
docx
keyboard_arrow_up
School
University of California, San Diego *
*We aren’t endorsed by this school
Course
18
Subject
Mathematics
Date
Apr 3, 2024
Type
docx
Pages
14
Uploaded by SargentMask12558
Exercise 4.1
a.
Use MATLAB to compute the determinants of the matrices A+B, A-B, AB, A-
1, and BT. (Recall that in MATLAB, BT is written as B'.)
>> A=[8 11 2 8;0 -7 2 -1;-3 -7 2 1;1 1 2 4]
A =
8 11 2 8
0 -7 2 -1
-3 -7 2 1
1 1 2 4
>> B=[1 -2 0 5;0 7 1 5;0 4 4 0;0 0 0 2]
B =
1 -2 0 5
0 7 1 5
0 4 4 0
0 0 0 2
>> det(A)
ans =
76
>> det(B)
ans =
48
>> det(A+B)
ans =
0
>> det(A-B)
ans =
1038
>> det(A*B)
ans =
3.6480e+03
>> det(A^-1)
ans =
0.0132
>> det(inv(A))
ans =
0.0132
>> det(B')
ans =
48
b.
Which of the above matrices are not invertible? Explain your reasoning.
A+B is not invertible because the determinant of a A+B is zero, that means
the matrix is singular (or non-invertible). This is because a determinant of zero
suggests that the rows (or columns) of the matrix are linearly dependent, i.e.,
one row (or column) can be written as a linear combination of other rows (or
columns). This in turn implies that the matrix doesn't have a full rank and
hence it is non-invertible.
c.
Suppose that you didn't know the entries of A and B, but you did know
their determinants. Which of the above determinants would you still be
able to compute from this information, even without having A or B at
hand? Explain your reasoning.
The determinant of a product of two matrices is equal to the product of their
determinants (det(AB) = det(A)*det(B)). So, if you have the determinant of
AB, and the determinant of either A or B, you could find the determinant of
the other matrix.
The determinant of the inverse of a matrix is the reciprocal of the determinant
of the original matrix, provided that the original matrix is invertible (det(A^-1)
= 1/det(A)). So, if you know the determinant of A^-1, you can compute the
determinant of A.
The determinants of (A+B) and (A-B) generally won't help you recover the
determinants of A or B, because the determinant operation is not distributive
over matrix addition or subtraction.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Exercise 4.2
Use det() to calculate the determinant of N^100. Based on this information,
do you think that N^100 is invertible?
>> N=[0.003 0.02 0;0.1 1 0;0 0 0.015]
N =
0.0030 0.0200 0
0.1000 1.0000 0
0 0 0.0150
>> det(N^100)
ans =
-1.7211e-201
In this case, the determinant of N^100 is very small (-1.7211e-201), but it is
not exactly zero. Therefore, based on this information, N^100 is technically
invertible.
Now compute the determinant of N. Calculate the determinant of N^100 by
hand. Now would you reconsider your answer to the previous question?
Explain.
>> det(N)
ans =
1.5000e-05
I think even if the determinant of N^100 is technically non-zero, for all
practical purposes we may consider the matrix as non-invertible if its
determinant is very close to zero. This is because trying to invert such a
matrix can lead to numerical instability and large errors due to the limitations
of floating-point precision on computers.
Exercise 4.3
Enter the following matrix in MATLAB:
>> V = [-8 6 -6 -30; 3 9 12 -10; 3 -6 -1 18; 3 0 4 7]
a.
Now use MATLAB to find the eigenvectors and corresponding eigenvalues
of V. Assign them to matrices P and D, respectively.
>> V = [-8 6 -6 -30; 3 9 12 -10; 3 -6 -1 18; 3 0 4 7]
V =
-8 6 -6 -30
3 9 12 -10
3 -6 -1 18
3 0 4 7
>> [P,D] = eig(V)
P =
-0.8874 -0.8660 -0.8706 0.7607
0.2662 0.2887 -0.0725 -0.5567
0.2662 0.2887 0.4353 -0.0874
0.2662 0.2887 0.2176 -0.3221
D =
1.0000 0 0 0
0 2.0000 0 0
0 0 3.0000 0
0 0 0 1.0000
b.
Determine whether V is invertible by looking at the eigenvalues. Explain
your reasoning.
From output, you can see that the eigenvalues of matrix V are the diagonal
elements of matrix D: 1, 2, 3, 1. None of these eigenvalues is zero, which
means the matrix V is invertible. The determinant of a matrix (which is the
product of its eigenvalues) is zero if and only if the matrix is non-invertible.
Since none of the eigenvalues is zero, the determinant is also not zero, hence
V is invertible.
c.
Use MATLAB to evaluate P-1VP. What do you notice?
>> (P^-1)*V*P
ans =
1.0000 0.0000 0.0000 -0.0000
-0.0000 2.0000 -0.0000 0.0000
0.0000 0.0000 3.0000 0.0000
0.0000 0.0000 -0.0000 1.0000
I notice that the answer is equal to D but with some negative 0s.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Exercise 4.4
a.
Enter this matrix in MATLAB:
>> F = [0 1; 1 1]
Use MATLAB to find an invertible matrix P and a diagonal matrix D such that
PDP-1 = F.
>> F = [0 1; 1 1]
F =
0 1
1 1
>> [P D]=eig(F);
>> [P,D]=eig(F)
P =
-0.8507 0.5257
0.5257 0.8507
D =
-0.6180 0
0 1.6180
>> P*D*P^-1
ans =
-0.0000 1.0000
1.0000 1.0000
b.
Use MATLAB to compare F10 and PD10P-1.
>> F^10
ans =
34 55
55 89
>> P*D^10*P^-1
ans =
34.0000 55.0000
55.0000 89.0000
c.
Let f = (1, 1)T. Compute Ff, F2f, F3f, F4f, and F5f. (You don't need to
include the input and output for these.) Describe the pattern in your
answers.
(F^n)*f gives the n+1 and n+2 term of Fibonacci series.
d.
Consider the Fibonacci sequence {fn} = {1, 1, 2, 3, 5, 8, 13…}, where
each term is formed by taking the sum of the previous two. If we start with
a vector f = (f0, f1)T, then Ff = (f1, f0 + f1)T = (f1, f2)T, and in general Fnf
= (fn, fn+1)T. Here, we're setting both f0 and f1 equal to 1. Given this,
compute f30.
>> F^30*f
ans =
1346269
2178309
Exercise 4.5
a.
Use MATLAB to find a matrix Q and a diagonal matrix D such that P =
QDQ-1.
>> P = [0.8100 0.0800 0.1600 0.1000;
0.0900 0.8400 0.0500 0.0800;
0.0600 0.0400 0.7400 0.0400;
0.0400 0.0400 0.0500 0.7800]
P =
0.8100 0.0800 0.1600 0.1000
0.0900 0.8400 0.0500 0.0800
0.0600 0.0400 0.7400 0.0400
0.0400 0.0400 0.0500 0.7800
>> x0 = [0.5106; 0.4720; 0.0075; 0.0099]
x0 =
0.5106
0.4720
0.0075
0.0099
>> [Q,D] = eig(P)
Q =
0.6656 0.7676 0.5432 -0.4641
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
0.6165 -0.2841 -0.8148 -0.1254
0.2946 -0.5682 0.1811 -0.2508
0.3001 0.0848 0.0905 0.8402
D =
1.0000 0 0 0
0 0.6730 0 0
0 0 0.7600 0
0 0 0 0.7370
b.
Now recall that Pn = QDnQ-1. Find the limit as n tends to infinity of Dn by
hand; we'll call the resulting matrix L.
L = D^10000
L =
1.0000 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
c.
Using MATLAB, multiply L by Q and Q-1 (on the appropriate sides) to
compute P∞, the limit as n tends to infinity of Pn. Store the answer in a
variable called Pinf.
>> Pinf = Q*L*(Q^-1)
Pinf =
0.3547 0.3547 0.3547 0.3547
0.3285 0.3285 0.3285 0.3285
0.1570 0.1570 0.1570 0.1570
0.1599 0.1599 0.1599 0.1599
d.
Now use MATLAB to compute P∞x0. How does your answer compare to the
results you saw in the second part of the exercise from last lab?
>> Pinf*x0
ans =
0.3547
0.3285
0.1570
0.1599
This answer is the same as the results from the last lab.
e.
Make up any vector y in R4 whose entries add up to 1. Compute P∞y, and
compare your result to P∞x0. How does the initial distribution vector y of
the electorate seem to affect the distribution in the long term? By looking
at the matrix P∞, give a mathematical explanation.
y =
0.1000
0.1500
0.2500
0.5000
>> Pinf*y
ans =
0.3547
0.3285
0.1570
0.1599
Since P∞x0 and P∞y produces the same result, it means that regardless of the
initial distribution of the electorate, the long-term distribution will converge to
the same values given by the rows of P∞. This suggests that the initial
preferences or proportions of the electorate do not play a significant role in
determining the long-term distribution of the system. Instead, it is the
transition probabilities represented by the matrix P that drive the dynamics of
the system and determine its steady-state behavior.
Exercise 4.6
a.
Let e0 = (1, 1, 1, 1, 1, 1, 1, 1)T, and define en+1 = Len (which is the same
as saying en = Lne0). Use MATLAB to compute e10. How large must n be
so that each entry of en changes by less than 1% when we increase n by
1? [Don't try to get an exact value, just try to get a value for n that's big
enough.]
>> L = [0,0,0,0,1,0,0,0;
0,0,0,0,0,0,0,1;
0,1/2,0,0,0,0,1,0;
1/2,0,1/2,0,0,0,0,0;
0,0,1/2,0,0,1,0,0;
1/2,0,0,0,0,0,0,0;
0,1/2,0,0,0,0,0,0;
0,0,0,1,0,0,0,0;]
L =
0 0 0 0 1.0000 0 0 0
0 0 0 0 0 0 0 1.0000
0 0.5000 0 0 0 0 1.0000 0
0.5000 0 0.5000 0 0 0 0 0
0 0 0.5000 0 0 1.0000 0 0
0.5000 0 0 0 0 0 0 0
0 0.5000 0 0 0 0 0 0
0 0 0 1.0000 0 0 0 0
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
>> e0 = [1 1 1 1 1 1 1 1]'
e0 =
1
1
1
1
1
1
1
1
>> (L^10)*e0
ans =
1.0625
1.1250
1.1875
1.1250
1.1719
0.5781
0.5938
1.1562
To find a value for n that's big enough, we can continue raising L to higher
powers, such as L^100, L^1000, etc., until we see that the changes in the
entries of the resulting vector become negligible.
b.
In the graph of the network of webpages represented by L, which vertices
have an edge going out and pointing toward website C? Which vertices do
the edges coming out of C point to? (Here, by graph we mean a collection
of vertices and edges.)
Vertices B and G have edges pointing towards C
. C has edges pointing to vertices A, B,
and G.