Solving Fortran Runtime Error 112 - Mach Number Calculation

Click For Summary

Discussion Overview

The discussion revolves around a Fortran program intended to calculate the Mach number using the bisection method. Participants address a runtime error encountered in the program and explore potential solutions and improvements to the numerical method employed.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the Fortran code and the specific error encountered, seeking assistance in resolving it.
  • Another participant confirms that the problem has been solved but does not specify the solution.
  • A further participant inquires about the nature of the error and the resolution process.
  • One participant identifies a specific line of code as problematic, suggesting that the condition for the bisection method is incorrect and that an additional numerical method is necessary to find the function's extremum before applying the bisection method.
  • The same participant expresses a desire for a more elegant solution to the problem.

Areas of Agreement / Disagreement

There is no consensus on the best approach to solve the problem, as participants discuss different methods and the necessity of finding function extrema before applying the bisection method.

Contextual Notes

The discussion highlights potential limitations in the original approach, particularly regarding the assumptions made about the function's behavior and the choice of intervals for the bisection method.

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
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
Replies
12
Views
9K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
9K
Replies
13
Views
8K
  • · Replies 2 ·
Replies
2
Views
25K