Fr_RedPaw
Fr_RedPaw

Reputation: 21

Problem with assigning one last value to an integral in Fortran

I asked a question about this code before and here is a link to it: Problem with conditions and integrals in Fortran

But I decided to rewrite it and make it more convenient, but the problem is that for further calculations I need the value of V, H, D to take on the value of one digit. But for me it takes 5, and they are different when I restart, although the final number I need is the same.
I need that after everything, the value 'V' takes only the value = 8, and not everything. Exactly the same with D, H.

I entered print *, V and saw what it outputs after the entire

  value:1;2.5;4;5.5;8;

Or

Random number;Random number;Random number;Random number;8

And it turns out that I need 'V' to be only = 8 after calculations

Code:

    dimension A1(5), B1(5),  T1(5), D(5), OOO(5), HH(5),DD(5)
    real :: T, M, L, Y, a, b, e, V, H
    real A(5) /1,2,3,2,1/
    real B(5) /1,2,3,2,1/
    real T(5) /2,2,2,2,2/
    real X(5) /-2,-1,0,1,2/
    integer :: i
    T = 2
    M = 3.0
    Y = 5
    L = (Y**2) / 9.81
    e = 2.718
    KN = 5
     do i = 1, 5

      if (A(i) > 0 .and. B(i) > 0) then 
       go to 123
      else
       A1(i) = 0
       B1(i) = 0
       T1(i) = 0
      endif
      123 if ((A(i)/B(i)) <= T(i)) then
           A1(i) = A(i)
           B1(i) = B(i)
           T1(i) = A(i)/B(i)
          else
           B1(i) = B(i)
           T1(i) = T(i)
           A1(i) = B1(i) * T1(i)
          endif
       
      !V
      call VV(X, A, OOO,V)
      print *, V
      !H
      HH(i) = (1.0/12.0)* B1(i)**3
      call VV(X, HH, OOO,HHH)
      H = HHH * (1.0/V)
   
      !D
      DD(i) = ((-T1(i))/2.0) * A1(i)
      call VV(X,A,OOO,DDD)
      D = (DDD * (1.0/V)) + T
   
   
     end do
 
    end program F
    !Integral
    subroutine VV(X, Y, IY,O)
    real, intent(in):: X(1:5), Y(1:5)
    real :: IY(1:5), S, S1, O
    integer:: i, n
      n=size(X)
      S=0.0
      do i=1, n-1
        S1=S
        S=S+0.5*(X(i+1)-X(i))*(Y(i+1)+Y(i))
        IY(i)=S1
      end do
      IY(n)=S
      O = IY(n)
      return
    end subroutine VV

Upvotes: 1

Views: 43

Answers (1)

Fr_RedPaw
Fr_RedPaw

Reputation: 21

It turns out that "print *, V" was in the loop

Problem solved

Upvotes: 1

Related Questions