25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

320 Array Processing<br />

matrice quadrata un valore scalare λ è detto autovalore di A se esiste un vettore non nullo u<br />

tale che<br />

Au = λu<br />

Tale vettore u è chiamato autovettore di A associato a λ.<br />

PROGRAM eigen<br />

IMPLICIT NONE<br />

! Programma per testare gli autovalori e gli autovettori<br />

! di una matrice A di tipo intero<br />

REAL, ALLOCATABLE, DIMENSION (:,:) :: A<br />

REAL, ALLOCATABLE, DIMENSION (:) :: u<br />

REAL, ALLOCATABLE, DIMENSION (:) :: zero<br />

REAL :: lamda<br />

REAL, PARAMETER :: eps=0.001<br />

INTEGER :: i, n, stat<br />

LOGICAL :: correct=.TRUE.,answer=.TRUE.<br />

!<br />

PRINT*, "Dimensione di A: "<br />

READ(*,*) n<br />

ALLOCATE(A(1:n,1:n),u(1:n),zero(1:n),STATUS=stat)<br />

IF (stat/=0)<br />

PRINT*, "Allocazione degli array fallita!"<br />

PRINT*, "Codice dell’errore: ", stat<br />

STOP<br />

END IF<br />

PRINT*, "Introdurre A per righe: "<br />

DO i=1,n<br />

READ(*,*) A(i,1:n)<br />

END DO<br />

PRINT*, "Introdurre un autovalore di A: "<br />

READ(*,*) lamda<br />

PRINT*, "Introdurre il corrispondente autovettore: "<br />

READ(*,*) u(1:n)<br />

PRINT*, "A: "<br />

DO i=1,n<br />

PRINT*, A(i,1:n)<br />

END DO<br />

FORALL (i=1:n)<br />

A(i,i) = A(i,i) - lamda<br />

END FORALL<br />

zero = MATMUL(A,u)<br />

i = 1<br />

DO WHILE (correct.AND.i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!