# Sustavi linearnih jednadžbi

linsolve([x1 + 2*x2 - 5/2*x3 = 3, x1 - 3*x2 - 4*x3 = -1/2, 4*x2 + x3 = 3], [x1,x2,x3]);

linsolve([2*x1 - 5*x2 - x3 = 4, -x1 + 3*x2 = -1, x1 - 2*x2 - x3 = 3], [x1,x2,x3]);

a: [2,-5,-1,4];
b: [-1,3,0,-1];
c: [1,-2,-1,3];

pom: a$
a: c;
b;
c: pom;

a;
b: b+a;
c: c-2*a;

a: a+2*b;
b;
c: c+b;

a: [2,-5,-1,4];
b: [-1,3,0,-1];
c: [1,-2,-1,3];

M: matrix(a,b,c);

echelon(M);

rref(M):=block([p,q,k],[p,q]:matrix_size(M),M:echelon(M),
    k:min(p,q),
    for i thru min(p,q) do (if M[i,i]=0 then (k:i-1,return())),
    for i:k thru 2 step -1 do (for j from i-1 thru 1 step -1 do M:rowop(M,j,i,M[j,i])),
    M)$

rref(M);

r1: implicit(2*x1 - 5*x2 - x3 = 4,x1,-5,5,x2,-5,5,x3,-5,5);
r2: implicit(-x1 + 3*x2 = -1,x1,-5,5,x2,-5,5,x3,-5,5);
r3: implicit(x1 - 2*x2 - x3 = 3,x1,-5,5,x2,-5,5,x3,-5,5);

p: parametric(3*t+7,t+2,t,t,-5,1);

draw3d(surface_hide=true,r1,r2,r3,color=green,line_width=2,p);