You are on page 1of 3

# c c

1 2

11 12

66 67

c c

c c c c c c c c c c c c c c 6 c 4 3 c

## do 3 k=1,n-1 modify rows k+1 to n using a k,k

as a pivot

To modify this programme to do partial pivoting you should sweep through the entries in this column from row k to n to find entry with the largest magnetude. The copy the entries from this row into the array swap. Copy the entries from row k to this row. Copy the enries from swap into row k. Do a similar row exchange for the vector b After you have done all that continue from here do 4 i=k+1,n calculte multiplication factor for row i fact=a(i,k)/a(k,k) set entry in column k to be 0 a(i,k)=0.0 the add required multiples of row i do 6 j=k+1,n a(i,j)=a(i,j)-fact*a(k,j) continue do the same manipulation for b b(i)=b(i)-fact*b(k) continue write(99,*)'After step ',k,' matrix and b are' call matout(a,b,n) continue calculate solution do 7 i=n,1,-1 x(i)=b(i)/a(i,i) do 8 j=i+1,n x(i)=x(i)-a(i,j)*x(j)/a(i,i) continue continue write(99,*)'Solutions is x(1), ... , x(n) = ',(x(i),i=1,n) stop end subroutine matout(a,b,n) dimension a(10,10),b(10) write(99,*) do 1 i=1,n write(99,1000)(a(i,j),j=1,n),b(i) continue write(99,*) This format statement assumes that you have a 3x3 matrix as in the two examples. format(1x,f8.4,2x,f8.4,2x,f8.4,4x,f8.4)

8 7

1 c c 1000

return end