## Svojstvene vrijednosti i svojstveni vektori

### Egzaktno izračunavanje

A: matrix([2,0],[1,1/2]);

eigenvalues(A);

eigenvectors(A);

A: matrix([1,1],[0,1]);

eigenvectors(A);

A: matrix([1,2,3],[2,0,-1],[3,1,2]);

eigenvalues(A);

### Numeričko izračunavanje

kpol: expand(charpoly(A,λ));

allroots(kpol);

load("lapack");

sv: dgeev(A,true);

M: sv[2];

invert(M).A.M;

## Dugoročno ponašanje Lesliejeva modela

### Primjer s kukcima

L: matrix([1.5, 2],[0.08,0]);

N[0]: transpose(matrix([105,1]));

Dinamika starosne distribucije:

makelist(N[t]: L.N[t-1],t,1,10)$

with_slider_draw( t, makelist(t,t,0,7),xrange=[-0.5,1.5],
yrange=[0,2000],xlabel="",ylabel="",xtics=[0,1,3],
fill_density=1,fill_color=blue,
apply(bars,makelist([i-1,N[t][i][1],0.5],i,1,2)))$

Dinamika relativne starosne distribucije:

p(i):=[1,1].N[i];

with_slider_draw( t, makelist(t,t,0,7),xrange=[-0.5,1.5],
yrange=[0,1],xlabel="",ylabel="",xtics=[0,1,3],
fill_density=1,fill_color=blue,
apply(bars,makelist([i-1,N[t][i][1]/p(t),0.5],i,1,2)))$

Stabilna starosna distribucija odgovara normaliziranom svojstvenom vektoru pridruženom vodećoj svojstvenoj vrijednosti matrice L.

stabilna1: transpose(N[10]/p(10));

spektar: float(eigenvalues(L));

sv: float(eigenvectors(L));

vsv: sv[2][2][1];

stabilna2: matrix(vsv / ([1,1].vsv));

stabilna1-stabilna2;

### Primjer s glodavcima

L: matrix([0,2.3,2.6,1.5],[0.3,0,0,0],[0,0.4,0,0],[0,0,0.2,0]);

N[0]: transpose(matrix([300,200,100,50]));

Dinamika starosne distribucije:

makelist(N[t]: L.N[t-1],t,1,50)$

with_slider_draw( t, makelist(t,t,0,50),xrange=[-0.5,3.5],
yrange=[0,1250],xlabel="",ylabel="",xtics=[0,1,3],fill_density=1,
fill_color=blue,apply(bars,makelist([i-1,N[t][i][1],0.5],i,1,4)))$

Dinamika relativne starosne distribucije:

p(i):=[1,1,1,1].N[i];

with_slider_draw( t, makelist(t,t,0,50),xrange=[-0.5,3.5],
yrange=[0,1],xlabel="",ylabel="",xtics=[0,1,3],fill_density=1,
fill_color=blue,apply(bars,makelist([i-1,N[t][i][1]/p(t),0.5],i,1,4)))$

stabilna1: transpose(N[50]/p(50));

load("lapack")$

sv: dgeev(L,true);

abs(sv[1]);

X0: transpose(transpose(sv[2])[1]);

J: matrix([1,1,1,1]);

stabilna2: transpose((1/J.X0)*X0);

stabilna1-stabilna2;

### Modeliranje populacije žena u RH na osnovi demografskih podataka

bardraw(vec):=wxdraw2d(xrange=[-4,98],yrange=[0,180000],
xlabel="", ylabel="", xtics=[0,5,95],fill_density=1,
fill_color=blue,apply(bars,makelist([5*(i-1),vec[i][1],2],i,1,20)));

bardraw2(vec1,vec2):=wxdraw2d(xrange=[-4,98],yrange=[0,180000],
xlabel="", ylabel="", xtics=[0,5,95],fill_density=1,
fill_color=red,apply(bars,makelist([5*(i-1),vec1[i][1],2],i,1,20)),
fill_color=blue,apply(bars,makelist([5*(i-1)-2,vec2[i][1],2],i,1,20)));

Broj žena u RH prema popisima stanovništva 2001. i 2011. godine. Izvor: Statističko izvješće 1468, Državni zavod za statistiku, 2013.
http://www.dzs.hr/Hrv_Eng/publication/2012/SI-1468.pdf

N[2001]: matrix([115804],[121254],[131409],[145930],[149892],[145831],[147511],
[158767],[166904],[165286],[151549],[121102],[141349],[142488],[122001],[93052],
[39914],[22151],[7694],[1132]);

bardraw(N[2001]);

kill(M);

M[2011]: matrix([103458],[99476],[114769],[119259],[128203],[141650],[144621],[140770],
[143330],[155115],[162521],[158068],[144889],[112638],[123489],[109070],[72105],[35226],
[8178],[1719]);

bardraw(M[2011]);

Stopa rađanja u RH u 2012. godini. Izvor: Porodi u zdravstvenim ustanovama u Hrvatskoj 2012. godine, Zavod za javno zdravstvo, 2013.
http://hzjz.hr/wp-content/uploads/2013/11/porodi_2012.pdf

f: 2.5*[0,0,0,11.3,54.0,97.4,89.2,38.7,7.4,0.4,0,0,0,0,0,0,0,0,0,0]/1000.;

Vjerojatnosti preživljavanja žena u RH od 2010. do 2012. Izvor: Tablice mortaliteta Republike Hrvatske od 2010. do 2012, Državni zavod za
statistiku, 2014.
http://www.dzs.hr/Hrv_Eng/Other/TABLICA%20MORTALITETA%202014.pdf

p: [0.996891,0.999513,0.999666,0.999116,0.998843,0.998658,0.998175,0.997039,0.994879,0.990617,0.984257,
    0.976657,0.965887,0.942824,0.897929,0.805208,0.64711,0.447992,0.276076];

L: apply(matrix,makelist(makelist(block(if i=1 then return(f[j]) else 
    block(if i-1=j then return(p[j]) else return(0))),j,1,20),i,1,20));

N[2006]: L.N[2001];

bardraw(N[2006]);

N[2011]: L.N[2006];

bardraw(N[2011]);

bardraw2(N[2011],M[2011]);

N[2011]-M[2011];

Dinamika populacije žena u RH od 2001. do 2101.

for t in makelist(t,t,2006,2101,5) do N[t]: L.N[t-5];

with_slider_draw( t, makelist(t,t,2001,2101,5),
xrange=[-4,98],yrange=[0,180000],xlabel="",ylabel="", 
xtics=[0,5,95], fill_density=1, fill_color=red,
apply(bars,makelist([5*(i-1),N[t][i][1],2],i,1,20)))$

Vodeća svojstvena vrijednost i stabilna starosna distribucija: 

load("lapack");

sv: dgeev(L,true);

abs(sv[1]);

X0:transpose(matrix(transpose(sv[2])[11]));

stabilna: X0/matrix([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]).X0;

bardraw(vec):=wxdraw2d(xrange=[-4,98],yrange=[0,0.08],
xlabel="", ylabel="", xtics=[0,5,95],fill_density=1,
fill_color=red,apply(bars,makelist([5*(i-1),vec[i][1],2],i,1,20)));

bardraw(stabilna);