Monday, February 20, 2006

Some Pointers with the FORTRAN matrix assignment

1)
Definition of Strongly Connected Graph

A directed graph is called strongly connected if for every pair of vertices u and v there is a path from u to v and a path from v to u.
2) A program that uses the built in matmul, and does assignment from one matrix to another:

! EXAMPLE 4
!
! Aprogram to compute the largest eigenvalue
! of a real, dense matrix by the power method

integer, parameter::devno=10, n=10, minit = 10, maxit=100
real::lambda_old, lambda_new
real::rel_err, tol = 2.0**(-20)
real,dimension(n)::x_new, x_old=(/(1.0/n,i=1,n)/)
real,dimension(n,n)::a
open(devno, file='a.dat')
read(10,10) ((a(i,j),j=1,n),i=1,n)
10 format(10f4.1)
iterate: do i=1,maxit
write (*,*) "i = ", i
x_new=matmul(a, x_old)
lambda_new = sqrt(dot_product(x_new, x_new))
write(*,*) "lambda_new = ", lambda_new
if (i .gt. minit) then
rel_err = abs((lambda_new - lambda_old)/lambda_old)
if (rel_err .lt. tol) exit iterate
endif
if (i .eq. maxit) write (*,*) "Maximum Iterations reached"
lambda_old = lambda_new
x_old = x_new/lambda_new
end do iterate
write(*,*) "lambda = ", lambda_new
end

Another place that uses matmul.

No comments: