(* ESERCIZIO 6.1.3 (a) *)

Clear[a,b,x];
a={{1,-2,3},{3,-3,1},{1,1,0}};
b={2,-1,3};
x={x1,x2,x3};
MatrixForm[a]
sys=Dot[a,x]==b;
MatrixForm[Thread[sys]]

ab={Join[a[[1]],{b[[1]]}],Join[a[[2]],{b[[2]]}],Join[a[[3]],{b[[3]]}]};
MatrixForm[ab]

ab1={ab[[1]],3*ab[[1]]-ab[[2]],ab[[1]]-ab[[3]]};
MatrixForm[ab1]
ab2={ab1[[1]],ab1[[2]],ab1[[2]]-ab1[[3]]};
MatrixForm[ab2]

x3sol=8/5
x2sol=-(7-8*x3sol)/3
x1sol=2-3*x3sol+2*x2sol

Solve[sys,x]

(* ESERCIZIO 6.1.3 (c) *)

Clear[a,b,x];
a={{2.,0.,0.,0.},{1.,1.5,0.,0.},{0.,-3.,0.5,0.},{2.,-2.,1.,1.}};
b={3.,4.5,-6.6,-8.};
x={x1,x2,x3,x4};
MatrixForm[a]
sys=Dot[a,x]==b;
MatrixForm[Thread[sys]]

ab={Join[a[[1]],{b[[1]]}],Join[a[[2]],{b[[2]]}],Join[a[[3]],{b[[3]]}],Join[a[[4]],{b[[4]]}]};
MatrixForm[ab]

ab1={ab[[1]],ab[[2]]-0.5*ab[[1]],ab[[3]],ab[[4]]-ab[[1]]};
MatrixForm[ab1]

ab2={ab1[[1]],ab1[[2]],ab1[[3]]+2.*ab1[[2]],ab1[[4]]+(2./1.5)*ab1[[2]]};
MatrixForm[ab2]

ab3={ab2[[1]],ab2[[2]],ab2[[3]],ab2[[4]]-2.*ab2[[3]]};
MatrixForm[ab3]

x4sol=-5.8
x3sol=-1.2
x2sol=2.
x1sol=1.5

Solve[sys,x]

(* ESERCIZIO 6.1.5 *)

Clear[a,b,x];
a={{2,-6α},{3α,-1}};
b={3,3/2};
x={x1,x2};
MatrixForm[a]
sys=Dot[a,x]==b;
MatrixForm[Thread[sys]]

ab={Join[a[[1]],{b[[1]]}],Join[a[[2]],{b[[2]]}]};
MatrixForm[ab]

ab1={ab[[1]],ab[[2]]-(3/2)*α*ab[[1]]};
MatrixForm[ab1]

(* (a) *) eq1=-1+9 (α^2)==0;
sol1=Solve[eq1, α]

(* (b) *) eq2=(3/2)-((9 α)/2)==0
sol2=Solve[eq2, α]

(* Proposta: ESERCIZIO 6.2.11,12,13 *)
(* Proposta: ESERCIZIO 6.2.16 *)

(* Proposta: ESERCIZIO 6.3.1 *)

Clear[a,b,c,d,e,f]
a={{4,2,6},{3,0,7},{-2,-1,-3}};
b={{1,2,0},{2,1,-1},{3,1,1}};
c={{4,0,0},{0,0,0},{0,0,3}};
d={{1,1,-1,1},{1,2,-4,-2},{2,1,1,5},{2,1,1,5}};
e={{4,0,0,0},{6,7,0,0},{9,11,1,0},{5,4,1,1}};
f={{2,0,1,2},{1,1,0,2},{2,-1,3,1},{3,-1,4,3}};
MatrixForm[a]
MatrixForm[b]
MatrixForm[c]
MatrixForm[d]
MatrixForm[e]
MatrixForm[f]
n1=3;n2=4;

n=n1;
t=c;
Do[r[i]=t[[i]][[1]]/t[[1]][[1]],{i,2,n}]
t1={t[[1]],t[[2]]-t[[1]]r[2],t[[3]]-t[[1]]*r[3]};
MatrixForm[t1]

Do[r[i]=t1[[i]][[2]]/t1[[2]][[2]],{i,3,n}]
t2={t1[[1]],t1[[2]],t1[[3]]-t1[[2]]*r[3]};
MatrixForm[t2]

n=n2;
t=f;
Do[r[i]=t[[i]][[1]]/t[[1]][[1]],{i,2,n}]
t1={t[[1]],t[[2]]-t[[1]]r[2],t[[3]]-t[[1]]*r[3],t[[4]]-t[[1]]*r[4]};
MatrixForm[t1]

Do[r[i]=t1[[i]][[2]]/t1[[2]][[2]],{i,3,n}]
t2={t1[[1]],t1[[2]],t1[[3]]-t1[[2]]*r[3],t1[[4]]-t1[[2]]*r[4]};
MatrixForm[t2]

Do[r[i]=t2[[i]][[3]]/t2[[3]][[3]],{i,4,n}]
t3={t2[[1]],t2[[2]],t2[[3]],t2[[4]]-t2[[3]]*r[4]};
MatrixForm[t3]

(* ESERCIZIO 6.3.12 *)

(* Proposta: ESERCIZIO 6.3.14 *)