## Operacije s matricama

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

B: matrix(
[3,-1,-3],
[6,5,-3]
);

A+B;

2*A;

3*A-2*B;

A*B;

A.B;

transpose(B);

A.transpose(B);

transpose(B).A;

## Inverz matrice

A: matrix([a,b],[c,d]);

determinant(A);

invert(A);

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

invert(A);

B: matrix([2,4,1],[1,7,1],[3,0,1]);

invert(B);

C: matrix([2,-4,2],
[-1,5,2],
[3,-3,6]);

invert(C);

determinant(C);

## Lesliejev populacijski model

### 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]));

bardraw(vec):=wxdraw2d(xrange=[-0.5,3.5],yrange=[0,1000],xlabel="",
    ylabel="",xtics=[0,1,3],fill_color=blue,fill_density=1,
    apply(bars,makelist([i-1,vec[i][1],0.5],i,1,4)));

bardraw(N[0]);

N[1]: L.N[0];

bardraw(N[1]);

N[2]: L.N[1];

bardraw(N[2]);

N[3]: L.N[2];

bardraw(N[3]);

N[4]: L.N[3];

bardraw(N[4]);

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)))$

### Primjer s kukcima

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

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

bardraw(vec):=wxdraw2d(xrange=[-0.5,1.5],yrange=[0,300],xlabel="",
    ylabel="",xtics=[0,1,3],fill_color=blue,fill_density=1,
    apply(bars,makelist([i-1,vec[i][1],0.5],i,1,2)));

bardraw(N[0]);

N[1]: L.N[0];

bardraw(N[1]);

N[2]: L.N[1];

bardraw(N[2]);

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)))$

Ukupna veličina populacije:

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

p(0);

p(1);

p(2);

p(3);

Dinamika relativne starosne distribucije:

makelist(N[t]/p(t),t,0,10);

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)))$