Solving Fortran Runtime Error 112 - Mach Number Calculation

In summary, the speaker is seeking assistance with a program to calculate mach number using the bisection method in Fortran. They encountered an error in line 40 and are asking for help. They have successfully calculated the function using Wolfram but need to run it in Fortran. The equation being used is 1.7795 - (0.334898 (1 + 0.2 x^2)^6.)/x^2. The speaker has identified an error in the code and has solved the problem by using a different numerical method to find the extreme of the function. They are open to suggestions for a more efficient solution.
  • #1
Hejmore
3
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
  • #2
Problem is solved.
 
  • #3
That's great.

What was the actual error and how did you solve it?
 
  • #4
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
 

FAQ: Solving Fortran Runtime Error 112 - Mach Number Calculation

What is Fortran Runtime Error 112?

Fortran Runtime Error 112 is a common error that occurs when a program attempts to perform a mathematical operation that results in an overflow or underflow of the value. This can happen when the result of the calculation is too large or too small to be represented by the data type used.

What causes Fortran Runtime Error 112?

The most common cause of Fortran Runtime Error 112 is a mistake in the code, such as using incorrect data types or not properly handling exceptional cases. It can also occur due to limited precision in floating-point calculations or incorrect input values.

How can I fix Fortran Runtime Error 112?

To fix Fortran Runtime Error 112, you will need to carefully review your code and identify the source of the error. This may involve debugging your program and checking for any mistakes or improper data handling. You may also need to adjust your calculations to use a different data type or improve the precision of your calculations.

How can I prevent Fortran Runtime Error 112 in the future?

To prevent Fortran Runtime Error 112, it is important to carefully plan and test your code before running it. This includes checking for potential mathematical errors and ensuring that your program can handle exceptional cases. Using appropriate data types and being aware of the limitations of floating-point calculations can also help prevent this error.

Is there any other common Fortran Runtime Error that may occur during Mach Number calculation?

Yes, there are other common Fortran Runtime Errors that may occur during Mach Number calculation, such as Error 136 (Array Index Out of Bounds) or Error 157 (Invalid Floating-Point Operation). It is important to carefully review your code and handle these errors appropriately to ensure the accuracy and reliability of your calculations.

Similar threads

Replies
5
Views
4K
Replies
9
Views
1K
Replies
4
Views
2K
Replies
19
Views
6K
Replies
6
Views
2K
Replies
2
Views
8K
Replies
2
Views
24K
Back
Top