Fortran Solving Fortran Runtime Error 112 - Mach Number Calculation

AI Thread Summary
The discussion revolves around a Fortran program designed to calculate the Mach number using the bisection method. The user encountered an error in line 40 of their code. After troubleshooting, it was identified that the condition in line 10, which directed the program flow based on the value of the variable 'sucin', was incorrect. The user realized that relying solely on the bisection method was inadequate for this problem, as it required finding the extremum of the function before selecting the appropriate interval. They successfully resolved the issue by incorporating another numerical method to locate the extremum, allowing the bisection method to function correctly. The user expressed interest in finding a more elegant solution for solving the function.
Hejmore
Messages
3
Reaction score
0
Hi, I try to write program to calculating mach number, with using bisection method. When I run program, fortran write to me an error in line 40. Can you help? I tried to calculating function by using wolfram sucesfully but I need to run it on fortran, An equation is 1.7795 - (0.334898 (1 + 0.2 x^2)^6.)/x^2. Can you help me? Thx

My error code:
Fortran:
program mach
     real pp,z1,z2,sucin,a,b,x,machx,a1

      pp=1
      a1=0.1
      b=3

      z1=pp**2-(0.334898*(1+0.2*a1**2)**6)/a1**2
      z2=pp**2-(0.334898*(1+0.2*b**2)**6)/b**2

      sucin=z1*z2

      if(sucin.lt.0) go to 1

      if(sucin.gt.0) go to 3

    1 continue

      do
          a=a1
          a1=(b+a)/2

          z1=pp**2-(0.334898*(1+0.2*a1**2)**6)/a1**2
          z2=pp**2-(0.334898*(1+0.2*b**2)**6)/b**2

          sucin=z1*z2
          machx=a
          x=abs(b-a)

          if(x.lt.0.0001) exit

          if(sucin.lt.0) cycle

          if(sucin.gt.0) go to 2
      end do

    2 continue

      do
          b=a1
          a1=(b+a)/2

          z1=pp**2-(0.334898*(1+0.2*a**2)**6)/a**2
          z2=pp**2-(0.334898*(1+0.2*a1**2)**6)/a1**2

          sucin=z1*z2
          machx=b
          x=abs((b-a))

          if(x.lt.0.0001) exit

          if(sucin.lt.0) cycle

          if(sucin.gt.0) go to 1
      end do

    3 continue

      print*,'Mach number is'
      write(5,*) machx

      stop

end program mach
 
Last edited by a moderator:
Technology news on Phys.org
Problem is solved.
 
That's great.

What was the actual error and how did you solve it?
 
You can see, the condition if( sucin.gt.0)go to 3 in line 10 is wrong. If I use only bisection method, the program will not work correctly, because i must to find extreme of the function and then must to choose right interval. I had to use a next numerical method to find extrem and then I could solve this problem. I would be glad if you find some more elegant solution for solving this function. Thx
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
5K
Replies
9
Views
2K
Replies
19
Views
6K
Replies
6
Views
2K
Replies
2
Views
9K
Replies
2
Views
25K
Back
Top