LEVERRIE.txt program Leverrier; (* questo programma calcola il polinomio caratt. di una matrice *) uses crt,dos; type matrice = array[1..20,1..20] of real ; vettore = array[1..20] of real ; var A,B n,i,j s,p h : : : : matrice ; integer ; vettore ; char ; procedure riempimat ( n : integer ; var A,B : matrice ); var i,j:integer; begin for i:=1 to n do begin for j:=1 to n do begin writeln('inserisci A[',i,',',j,'] : '); readln(A[i,j]); B[i,j] := A[i,j] ; end; end; end; (* fine procedure *) procedure traccia ( n : integer ; A : matrice ;var s : real) ; var i:integer; begin s:= 0 ; for i:=1 to n do begin s:= s + A[i,i] ; end; end; (* fine procedure *) procedure moltiplicamat (n:integer; A,B:matrice; var C:matrice); var i,j,k:integer; begin for i:=1 to n do begin for j:=1 to n do begin Pagina 1 LEVERRIE.txt C[i,j]:= 0 ; for k:=1 to n do begin C[i,j]:= C[i,j] + A[i,k] * B[k,j] ; end; end; end; end; (* fine procedure *) procedure vedipol ( n : integer ; p : vettore ) ; var i : integer ; begin writeln; write(' x^(',n,') + ') ; for i := 1 to ( n - 1 ) do begin write(p[i]:4:2,' * x^(', n - i ,') + ' ); end; write(p[n]:4:2) ; end; (* fine procedure *) begin (* main *) clrscr; writeln(' inserisci n : '); readln(n); writeln; riempimat (n,A,B); traccia (n,A,s[1]); p[1]:= - s[1] ; for i:=2 to n do begin moltiplicamat (n,B,A,B) ; traccia (n,B,s[i]); p[i] := s[i] ; for j :=1 to ( i - 1 ) do begin p[i] := p[i] + p[j] * s[i-j] ; end; p[i] := p[i] * ( 1 / (-i) ) ; Pagina 2 LEVERRIE.txt end; writeln; writeln(' ecco il polinomio caratteristico : '); writeln; vedipol (n,p); writeln; writeln; writeln(' premi un tasto per finire : '); readln(h); end. Pagina 3