Thursday, October 6, 2016

Bisection Method

Consider finding the root of  f(x) = Cos[x] – x . Let εstep = 0.01 ,  εabs = 0.001 and start with the interval [1.0 ,  0.5] .


Program Bisection_method
    Implicit none
    Real :: a , b , f , c , error
    
Write( * , * ) " Enter numbers between which the root is to be found : "   !(Can be change)
      10 read ( * , * ) a , b
 Write ( * , 61 ) " Input error value : "    !(Can be change)
       61 Format ( / , / , a18 )
        Read ( * , * ) error
     
  15 If ( f ( a ) * f ( b ) . lt . 0 )then
            c = ( a+b ) / 2.0
         else
  Write ( * , 62 ) " There is no zeros in this interval. Try with  another value of a & b "
       62 Format  ( / , / , a65 )
           go to 10
        Endif
        if ( f (a) * f (c) . lt . 0) then
            b = c
           else
          a = c
        Endif
       if ( abs (b-a) . gt . error ) goto 15
       write ( * , 63 ) " The approximate root of the function is : " , c
           63 Format ( / , / , a42 , f12.9 )
        end

    function f (x)
            implicit none
            real : : f , x
            f = cos (x) - x   !(Can be change)
    end function


Input ::




Output : :


Monday, October 3, 2016

Transpose matrix

Save   the   matrix  (A)  in  a  file  as  it  is 

 2        3          5
 7       11         0
-1      -13       -17

Print  A  and  transpose  of  A  in matrix  form .

Program coding

Program transpose_matrix
Integer , Dimension ( 3 , 3 ) : : a , b

Write ( * , 11 )  ' Input matrix  A '
11 format  ( / , A16 )

Read ( * , * ) ( ( a ( i , j ) , j = 1 , 3 ) , i = 1 , 3 )

Do i = 1 , 3
    Do j = 1,  3
        b ( i , j ) = a ( j , i )
    End do
End do

Write ( * , 12 ) ' A = '
12 Format ( / , A5 )

Do i = 1 , 3
Write ( * , * ) ( a ( i , j ) , j = 1 , 3 )
End do

Write ( * , 13 ) ' Then transpose of A  = '
13 Format  ( / , A20 )

Write ( * , 14 ) ( (  b ( i , j ) , j = 1 , 3 ) , i = 1 , 3 )
14 Format ( 3I4 , / , 3I4 ,  / , 3I4)


Stop
End

Input  :


Output :