program distances !Subroutine distances(x1,y1,x2,y2,x3,y3,d1,d2,d3) !Subroutine to calculate three distances between three points. !Variables used are: !A(x1,y1),B(x2,y2),C(x3,y3) are the coordinates of three points. !d1: the distance between A and B !d2: the distance between A and B !d3: the distance between A and B !Input:The points A,B,C !Output:The distances between A and B, B and C,C and A !Variable declerations real:: x1,x2,x3,y1,y2,y3,d1,d2,d3,a1,a2,a3 !Read the coordinates of points print*, "Enter the coordinates x1,y1,x2,y2,x3,y3" read*, x1,y1,x2,y2,x3,y3 !Calculate d1,d2,d3 a1=(x2-x1)**2+(y2-y1)**2 a2=(x3-x2)**2+(y3-y2)**2 a3=(x3-x1)**2+(y3-y1)**2 d1=sqrt(a1) d2=sqrt(a2) d3=sqrt(a3) !Calculate and print distances if (( d1==d2) .and. ( d1==d3 )) then !If the distances are equal, the shape is a equilateral triangle. print*, "The distances d1 , d2 , d3 have the same value",d1 else if (d1==d2 .and. d3 0 ) then write (unit = *, fmt = *) " Means: ", real( X_Mean ), real( Y_Mean ) if (How_Many > 1) then write (unit = *, fmt = *) real( X_Dev ), real( Y_Dev ), real( Covar ), real( Correlation ) write (unit = *, fmt = *) " Regression: ", real( A ), real( B ) end if else write (unit = *, fmt = *) " Insufficient data in this file. " end if stop end program E23 ! Example 5.39. Compute exponential of a matrix. program Matress implicit none integer, parameter :: P = 4, K = Selected_Real_Kind (P) integer :: Dim real (kind = K), allocatable, dimension(:, :) :: Array, X ! start program Matress open (1, file = "f39.dat", position = "rewind") read (1, *) Dim allocate (Array(Dim, Dim), X(Dim, Dim)) read (1, *) Array X = Mat_Exp (Array) print *, X stop contains function Mat_Exp (M) result (E) real (kind = K), dimension(:, :), intent (in) :: M real (kind = K), dimension(Size(M, Dim = 1), Size(M, Dim = 2)) :: E integer :: I, N, M_Shape(2) real (kind = K) :: Sign = 1.0 real (kind = K), allocatable, dimension(:, :) :: Term ! start function Mat_Exp E = 0.0_K ! Initialize power series. M_Shape = Shape(M) if (Sum (M ** 2) > 0.5_K) return ! M will probably not converge fast enough. if (M_Shape(1) /= M_Shape(2)) return ! M must be a square matrix allocate (Term(M_Shape(1), M_Shape(2))) Term = 0.0_K ! Initialize Term to identity matrix. do I = 1, Dim Term(I, I) = 1.0_K end do do N = 0, 100 ! Exit when Term is small or after Term is 100. E = E + Term ! Exp (M) power series if (Sum(Term ** 2) < 2.0_K * Spacing (1.0_K)) return ! Converged OK. Term = Sign * MatMul (Term, M) / Real (N + 1, Kind = K) ! Calculate next Term. Sign = - Sign end do return end function Mat_Exp end program Matress