Wednesday, January 2, 2013

Matrix multiplication by subroutine subprogram



Find the multiplication of any of the matrix with (3 by 3) dimension by applying subroutine subprogram
Solution:
       SUBROUTINE AL(A,B,C,M,N,L)
       DIMENSION A(M,N),B(M,N),C(M,N)
       DO I=1,M
       DO J=1,N
       C(I,J)=0.0
       Do k = 1,L
       C(I,J)=C(I,J)+A(I,L)*B(L,J)
       ENDDO
       ENDDO
       ENDDO
       RETURN
       END
       DIMENSION A(3,3),B(3,3),C(3,3)
       PRINT*, 'ENTER THE VALUE OF MATRIX A'
       DO I=1,3
       DO J=1,3
       READ*, A(I,J)
       ENDDO
       ENDDO
       PRINT*, 'ENTER THE VALUE OF MATRIX B'
       DO I=1,3
       DO J=1,3
       READ*, B(I,J)
       ENDDO
       ENDDO
       CALL AL(W,Q,E,3,3,3)
       PRINT*, C(1,1),'   ',C(1,2),'   ',C(1,3)
       PRINT*, C(2,1),'   ',C(2,2),'   ',C(2,3)
       PRINT*, C(3,1),'   ',C(3,2),'   ',C(3,3)
       END
      

subroutine



Given that length is 24 and height is 15. Then do the following operation by subroutine subprogram.
Solution:
       Real L,H
        Do k = 1,4
        Write(*,*) 'Enter the values of H and L'
        Read(*,*) H , L
        Call MAK(H,L,V,A)
         Write(*,*) '  H     L        V        A'
         Write(*,*) H,L,V,A
                 End do
          End
        subroutine  MAK(H,L,V,A)
             Pi=3.1416
        q=(L**2+4*h**2)/(8*H)
        w=H/3
        V=pi*H**2*(q-w)
        A=(Pi*(2*H**2+L**2))/2
        Return
        End

Poission distribrtion with Function subprogram


Find the poission distribution with function subprogram for the values of x which is given below
  X
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
Solution:  
        Function fact(N)
        INTEGER FACT
        FACT=1
        IF(N.EQ.0) RETURN
        DO I=1,N
        FACT=FACT*I
        ENDDO
        RETURN
        END
        INTEGER FACT
        REAL K1,K2,K3
        SUM=0.
        WRITE(*,*) 'ENTER THE VALUE OF X'
        READ(*,*) N
        WRITE(*,*)'ENTER THE VALUE OF LAMDA'
        READ(*,*) U
        DO J=0,N
        K1=EXP(-U)
        K2=U**J
        K3=FACT(J)
        PO=SUM+(K1*K2/K3)
         ENDDO
        WRITE(*,*) PO

        STOP
        END

Hints:
    Here we put N = 11 because we see in the total number of  observation of x is 11.
       

maximum values



Find the maximum value of the following numbers 4,5,2,3
Solution:
       print*, 'enter the value of m,n,p,and P'
       read*, i,j,l,m
       k=max(i,j,l,m)
       print*, 'the maximum value is', k
       end

hints: here we put i= 4,j=5, l=2 and m=3 then we automatically find out the maximum value by the given formula.

Correlation


Find the correlation of following data
X     Y
10    20
20    30
30    40
40    50
Solution:
         Real x,y,sumx,sumy,ssqrx,ssqry, spxy, Num , Den, r
         Write(*,*) 'Enter the value of N'
         read(*,*) N
          sumx= 0.0
         sumy= 0.0
          ssqrx= 0.0
         ssqry= 0.0
         spxy= 0.0
         Do j = 1,N
         Write(*,*) 'Enter the value of x',j
         read(*,*) x
         Write(*,*) 'Enter the value of y',j
         REad(*,*) y
         sumx = sumx+ x
         sumy = sumy+ y
         Avex= sumx/N
         Avey= sumy/N
         ssqrx= ssqrx+ x**2
         ssqry= ssqry+ y**2
         spxy=spxy+(x*y)
         End do
         Num= spxy- ((sumx*sumy)/n)
         Den= sqrt((ssqrx-(Avex)**2)*(ssqry-(Avey)**2))
         r = Num/Den
         write(*,*) 'The correlation between x and y is =' , r , ssqrx
         End


hints: her we consider N= 4 because each of the variable has 4 observation.