# Apèndix: Àlgebra lineal amb wxMaxima

1.  Matrius.

## Definició de matrius

kill(all)$

'A=A:matrix(  [a11, a12, a13, a14],  
                   [a21, a22, a23, a24],  
                   [a31, a32, a33, a34]  
               );

a1=row(A,1);       a3=row(A,3);

a[1]=col(A,1);      a[4]=col(A,4);

'A1=submatrix(1,A);

'A2=submatrix(A,2);

'A12=submatrix(1,A,2);

'A123=submatrix(1, 2, A, 3);

load ("eigen")$         
X3=X3:columnvector([x1, x2, x3]);

f[i,j]:=2*i+3*j;        
B1=B1:genmatrix(f,4,3);

g[i,j]:=1/(2*i+3*j-1);   
B2=B2:genmatrix(g,3,4);

'D5=D5:diag_matrix(a11,a22,a33,a44,a55);

I[2]=I2:ident(2);        I[4]=I4:ident(4);

O34=O34:zeromatrix(3,4);

'C=C:matrix(  [a11, a12],   [a21, a22]   );
load("nchrpl")$     '(tr(C))=mattrace(C);

## Operacions algebraiques amb matrius

kill(all)$

'A1=A1:matrix( [a11, a12, a13, a14],   [a21, a22, a23, a24],   [a31, a32, a33, a34]   )$
'A2=A2:matrix( [b11, b12, b13, b14],   [b21, b22, b23, b24],   [b31, b32, b33, b34]   )$

'(A1+A2)=A1+A2;

'(%lambda*A1)=%lambda*A1;

'(%lambda*A1 + %mu*A2)=%lambda*A1 + %mu*A2;

'(A1*A2)=A1*A2;

'A3=A3:matrix( [c11, c12, c13],  [c21, c22, c23],  [c31, c32, c33],  [c41, c42, c43]  );

'(A1.A3)=A1.A3;

  '(A3.A1)=A3.A1;

load ("eigen")$
X4=X4:columnvector([x1, x2, x3, x4])$
A1X4=A1X4:A1.X4;

'A1T=A1T:transpose(A1);

## Concatenació de matrius.

'A12=A12:addcol(A1, A2);

'A22=A22:addrow(A1, A2);

## Matrius per blocs.

load("diag")$
A3=A3:matrix([a11, a12, a13], [a21, a22, a23], [a31, a32, a33])$     
A4=A4:matrix([b11, b12], [b21, b22])$

diag([A3,A4]);

diag([A4,A3]);