You are on page 1of 5

MH2401

Algorithms & Computing III

AY 2013/14 S1

Lab 3: Solutions
Tasks.
1.1. In a stage-structured matrix model of a population, the Lefkovitch matrix L and
initial population vector x0 are stored, respectively, as the matrix L and vector x0
in the MATLAB data file population.mat on the course website.
You can issue the command load population to load these data in MATLAB .
What is the total initial population?
How many life stages are there in this model?
Solution.
The total initial population is 680.
There are 10 life stages in this model.

1.2. Create a plot the total population in this model over the time periods t = 0, 1, . . . , 20.
Solution.
>> x = x0 ;
>> P = sum( x );
>> f o r t = 1:20
x = L*x;
P = [ P sum( x )];
end
>> p l o t (0:20 , P )


1.3. Experiment with different values of s01 in the Lefkovitch matrix L to find a threshold
s01 (to the nearest three decimal places) such that the population dies off when
s01 < s01 , but explodes when s01 > s01 .
Solution.
>> f o r s_01 = 0:0.1:1
L (2 ,1) = s_01 ;
x = x0 ;
f o r t = 1:1000
x = L*x;
end
disp ([ num2str( s_01 ) ' , ' num2str(sum( x ))])
end
0, 0
0.1 , 1.063 e -139
0.2 , 8.1582 e -100
0.3 , 3.4414 e -074
0.4 , 8.001 e -055
0.5 , 4.7538 e -039
0.6 , 1.2467 e -025
0.7 , 6.9257 e -014
1

0.8 , 0 . 0 0 2 1 3 0 3
0.9 , 6 8 3 7 1 1 8 . 4 9 1 5
1, 3558961380611151
>> f o r s_01 = 0 . 8 : 0 . 0 1 : 0 . 9
L (2 ,1) = s_01 ;
x = x0 ;
f o r t = 1:10000
x = L*x;
end
disp ([ num2str( s_01 ) ' , ' num2str(sum( x ))])
end
0.8 , 6.6751 e -053
0.81 , 5.4218 e -043
0.82 , 3.5356 e -033
0.83 , 1.8601 e -023
0.84 , 7.9323 e -014
0.85 , 0 . 0 0 0 2 7 5 4 5
0.86 , 7 8 2 3 4 2 . 1 9 7
0.87 , 1 8 2 5 1 1 2 6 9 5 2 3 7 6 8 3
0.88 , 3 5 1 1 7 1 7 8 6 7 1 3 1 0 3 1 9 0 0 0 0 0 0 0 0
0.89 , 5 5 9 5 2 5 0 1 0 7 5 4 7 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0.9 , 7 4 1 0 8 3 4 0 1 3 0 8 9 2 5 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>> f o r s_01 = 0 . 8 5 : 0 . 0 0 1 : 0 . 8 6
L (2 ,1) = s_01 ;
x = x0 ;
f o r t = 1:100000
x = L*x;
end
disp ([ num2str( s_01 ) ' , ' num2str(sum( x ))])
end
0.85 , 8.5477 e -062
0.851 , 2.6545 e -052
0.852 , 8.0798 e -043
0.853 , 2.4106 e -033
0.854 , 7.0499 e -024
0.855 , 2.0211 e -014
0.856 , 5.68 e -005
0.857 , 1 5 6 4 9 0 . 1 1 5 2
0.858 , 4 2 2 6 9 6 6 3 3 9 6 0 0 0 8 . 8
0.859 , 1 1 1 9 4 0 8 7 1 7 5 7 0 4 0 4 2 0 0 0 0 0 0 0 0
0.86 , 2 9 0 6 5 9 7 4 6 8 4 2 3 9 9 9 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>> f o r s_01 = 0 . 8 5 6 : 0 . 0 0 0 1 : 0 . 8 5 7
L (2 ,1) = s_01 ;
x = x0 ;
for t = 1:1000000
x = L*x;
end
disp ([ num2str( s_01 ) ' , ' num2str(sum( x ))])
end
0.856 , 1.1848 e -068
0.8561 , 3.2934 e -059

0.8562 , 9.1365 e -050


0.8563 , 2.5296 e -040
0.8564 , 6.9898 e -031
0.8565 , 1.9276 e -021
0.8566 , 5.3053 e -012
0.8567 , 0.014573
0.8568 , 3 9 9 4 9 5 7 2 . 1 7 9
0.8569 , 1 0 9 3 0 0 4 5 6 1 9 3 0 1 0 1 3 0
0.857 , 2 9 8 4 5 0 0 0 6 7 8 2 7 7 3 1 6 0 0 0 0 0 0 0 0 0 0

It appears that s01 lies between 0.8567 and 0.8568. Thus we take s01 0.857 to the
nearest three decimal places.

1.4. Create a plot of the largest eigenvalue of L against s01 , for values of s01 around the
threshold s01 .
How does the largest eigenvalue behave when s01 crosses the threshold?
What conjecture can you draw from this observation?
Solution.
>> s_01 = 0 . 8 5 2 : 0 . 0 0 1 : 0 . 8 6 2 ;
>> l = length ( s_01 );
>> max_eig = zeros (1 , l );
>> f o r i = 1: l
L (2 ,1) = s_01 ( i );
max_eig ( i ) = max( e i g ( L ));
end
>> p l o t ( s_01 , max_eig )
>> a x i s ([min( s_01 ) max( s_01 ) min( max_eig ) max( max_eig )])

The plot shows that the largest real eigenvalue crosses 1 when s01 crosses the threshold.
We can conjecture that when the population dies off when largest real eigenvalue of
the Lefkovitch matrix is below 1, but explodes when the largest real eigenvalue is
above 1.


2.1. Create a plot of the letters NTU arranged horizontally on the same baseline with a
spacing of 10 units between them.
Solution.
>> M_N = [0 10 10 50 60 60 50 50 10 0
0 0 60 0 0 80 80 20 80 80
1 1 1 1 1 1 1 1 1 1];
>> M_T = [25 35 35 60 60 0 0 25
0 0 70 70 80 80 70 70
1 1 1 1 1 1 1 1];
>> M_U = [0 60 60 50 50 10 10 0
0 0 80 80 10 10 80 80
1 1 1 1 1 1 1 1];
>> T_70_0 = [1 0 70
0 1 0
0 0 1];
>> T_140_0 = [1 0 140
0 1 0
0 0 1];
>> M_T1 = T_70_0 * M_T ;
>> M_U1 = T_140_0 * M_U ;
>> p l o t ([ M_N (1 ,:) M_N (1 ,1)] , [ M_N (2 ,:) M_N (2 ,1)])
>> hold on
>> p l o t ([ M_T1 (1 ,:) M_T1 (1 ,1)] , [ M_T1 (2 ,:) M_T1 (2 ,1)])
>> p l o t ([ M_U1 (1 ,:) M_U1 (1 ,1)] , [ M_U1 (2 ,:) M_U1 (2 ,1)])
>> hold off
>> a x i s equal


2.2. Create a plot of the letters NTU arranged along the same vertical baseline with each
letter rotated so that it lies on its right side, and with a spacing of 10 units between
them.
Solution.
>> R_m90 = [0 1 0
-1 0 0
0 0 1];
>> M_N2 = R_m90 * M_N ;
>> M_T2 = R_m90 * M_T1 ;
>> M_U2 = R_m90 * M_U1 ;
>> p l o t ([ M_N2 (1 ,:) M_N2 (1 ,1)] , [ M_N2 (2 ,:) M_N2 (2 ,1)])
>> hold on
>> p l o t ([ M_T2 (1 ,:) M_T2 (1 ,1)] , [ M_T2 (2 ,:) M_T2 (2 ,1)])
>> p l o t ([ M_U2 (1 ,:) M_U2 (1 ,1)] , [ M_U2 (2 ,:) M_U2 (2 ,1)])
>> hold off
>> a x i s equal

2.3. Create a plot of the letters NTU arranged diagonally with each subsequent letter is
separated by a space of 10 units to the right and 10 units down.
Solution.
>> T_70_m90 = [1 0 70
0 1 -90
0 0 1];
>> T _ 1 4 0 _ m 1 8 0 = [1 0 140
0 1 -180
0 0 1];
>> M_T3 = T_70_m90 * M_T ;
>> M_U3 = T _ 1 4 0 _ m 1 8 0 * M_U ;
>> p l o t ([ M_N (1 ,:) M_N (1 ,1)] , [ M_N (2 ,:) M_N (2 ,1)])
>> hold on
>> p l o t ([ M_T3 (1 ,:) M_T3 (1 ,1)] , [ M_T3 (2 ,:) M_T3 (2 ,1)])
>> p l o t ([ M_U3 (1 ,:) M_U3 (1 ,1)] , [ M_U3 (2 ,:) M_U3 (2 ,1)])
>> hold off
>> a x i s equal


2.4. Create a plot of the letters NTU arranged along a baseline that is a 45 line below
the horizontal, with each letter rotated so it rests on the baseline, and with a spacing
of 10 units between them.
Solution.
>> R_m45 = [1/ s q r t (2) 1/ s q r t (2) 0
-1/ s q r t (2) 1/ s q r t (2) 0
0 0 1];
>> M_N4 = R_m45 * M_N ;
>> M_T4 = R_m45 * M_T1 ;
>> M_U4 = R_m45 * M_U1 ;
>> p l o t ([ M_N4 (1 ,:) M_N4 (1 ,1)] , [ M_N4 (2 ,:) M_N4 (2 ,1)])
>> hold on
>> p l o t ([ M_T4 (1 ,:) M_T4 (1 ,1)] , [ M_T4 (2 ,:) M_T4 (2 ,1)])
>> p l o t ([ M_U4 (1 ,:) M_U4 (1 ,1)] , [ M_U4 (2 ,:) M_U4 (2 ,1)])
>> hold off
>> a x i s equal

You might also like