INVERSAT.txt program inversa_di_una_matrice_triangolare_superiore; (* questo programma inverte una matrice triangolare superiore *) uses crt,dos; label 100; var i,j,p,n:integer; A,B:array[1..20,1..20] of real; s:real; h:char; begin clrscr; writeln('introduci n :'); readln(n); writeln; for i:=1 to n do begin for j:=i to n do begin writeln(' introduci il valore di posto : ',i,' ',j); readln(A[i,j]); if (A[i,i]=0) then begin writeln; writeln(' matrice non invertibile '); goto 100; end; end; end; for i:=1 to n do begin for j:=1 to (i-1) do begin A[i,j]:=0; end; end; writeln; writeln('visualizzo la matrice triangolare da invertire :'); for i:=1 to n do begin writeln; for j:=1 to n do begin write(' ',A[i,j]:0:2); end; end; writeln; (*ora passo ad invertire la matrice*) for j:=1 to n do begin B[j,j]:=1/A[j,j]; for i:=(j-1) downto 1 do begin s:=0; for p:=n downto (i+1) do begin s:=s-A[i,p]*B[p,j]; end; B[i,j]:=s/A[i,i]; end; end; for i:=1 to n do begin for j:=1 to (i-1) do begin B[i,j]:=0; (* la matrice B e' anch'essa triangolare superiore *) Pagina 1 INVERSAT.txt end; end; writeln; writeln('la matrice inversa di A e'' :'); for i:=1 to n do begin writeln; for j:=1 to n do begin write(' ',B[i,j]:0:2); end; end; 100: writeln; writeln; writeln(' premi un tasto per tornare all''edit :'); readln(h); end. Pagina 2