Why Does My Fortran Code Give an Unclassifiable Statement Error?

In summary: The converse of .EQ. is .NE. for "not equal to." So, the correct equation for fun is fun=(c)*(1-c)/(d+2).In summary, the program aims to use Euler's method to approximate the value of the function f(x,y)=y(1-y)/x+2 over a given interval. The conversation discusses an error message caused by a missing multiplication operator in the function fun(c,d). The correct equation for the function is fun=(c)*(1-c)/(d+2).
  • #1
gabforse
1
0
Hey so I'm getting the error message:
Code:
Euler_Method.f90:43.1:
fun=(c)(1-c)/(d+2)
1
Error: Unclassifiable statement at (1)
And here is my code:
Fortran:
PROGRAM Euler_Method

!-------------------------------------------------------------------
! The purpose of this program is to read in endpoints, initial
!conditions, and a stepsize from the user, and then use Euler's
!method to approximate the value of the function f(x,y)=y(1-y)/x+2
!over that interval.
!-------------------------------------------------------------------

IMPLICIT NONE

REAL:: alpha, h, inr, x, y
INTEGER:: i, b

WRITE(*,*) "Please enter the rightmost endpoint"
WRITE(*,*) "of the interval over which you wish to find an"
WRITE(*,*) "approximation of f(x,y). (Must be integer value)"
READ(*,*) b

WRITE(*,*) "Please enter x of y(x)."
READ(*,*) inr
WRITE(*,*) "Please enter y of y(x)."
READ(*,*) alpha

WRITE(*,*) "Please enter the stepsize."
READ(*,*) h

DO i=0, b
y=2
x=0
x=x+h*fun(x,y)
y=y+h
!Output at each step
WRITE(*,*) x
END DO

WRITE(*,*)"The final approximation is:",x,"."

CONTAINS
REAL FUNCTION fun(c,d)
IMPLICIT NONE
REAL, INTENT(in):: c,d
fun=(c)(1-c)/(d+2)
RETURN
END FUNCTION fun

END PROGRAM Euler_Method
 
Technology news on Phys.org
  • #2
gabforse said:
Hey so I'm getting the error message:
Euler_Method.f90:43.1:
fun=(c)(1-c)/(d+2)
1
Error: Unclassifiable statement at (1)
You forgot to add a "*" to multiply. It should be "fun=(c)*(1-c)/(d+2)".
 
  • #3
gabforse said:
Hey so I'm getting the error message:
Euler_Method.f90:43.1:
fun=(c)(1-c)/(d+2)
1
Error: Unclassifiable statement at (1)

And here is my code:
PROGRAM Euler_Method

!-------------------------------------------------------------------
! The purpose of this program is to read in endpoints, initial
!conditions, and a stepsize from the user, and then use Euler's
!method to approximate the value of the function f(x,y)=y(1-y)/x+2
!over that interval.
!-------------------------------------------------------------------

IMPLICIT NONE

REAL:: alpha, h, inr, x, y
INTEGER:: i, b

WRITE(*,*) "Please enter the rightmost endpoint"
WRITE(*,*) "of the interval over which you wish to find an"
WRITE(*,*) "approximation of f(x,y). (Must be integer value)"
READ(*,*) b

WRITE(*,*) "Please enter x of y(x)."
READ(*,*) inr
WRITE(*,*) "Please enter y of y(x)."
READ(*,*) alpha

WRITE(*,*) "Please enter the stepsize."
READ(*,*) h

DO i=0, b
y=2
x=0
x=x+h*fun(x,y)
y=y+h
!Output at each step
WRITE(*,*) x
END DO

WRITE(*,*)"The final approximation is:",x,"."

CONTAINS
REAL FUNCTION fun(c,d)
IMPLICIT NONE
REAL, INTENT(in):: c,d
fun=(c)(1-c)/(d+2)
RETURN
END FUNCTION fun

END PROGRAM Euler_Method
fun=(c)(1-c)/(d+2) should be fun=(c)*(1-c)/(d+2), I think.

EDIT: lol
 
  • #4
@gabforse, Krylov and Samy_A both figured out the reason for your compile error. The lesson for you is that you can't use mathematics or physics notation in programming languages. To denote multiplication, you can't just put symbols next to each other, as in ab; you have to explicitly add the multiplication operator *.

Another difference the new programming students stumble on is that in mathematics, = means "equal to." In many programming languages, = is used to assign a value to a variable, and a different operator is used to compare two values for equality. Fortran uses .EQ., and newer Fortran versions use == as well (taking a cue from C, C++, and others).
 

1. What is a Fortran compile error?

A Fortran compile error is a type of error that occurs during the compilation process of a Fortran program. It indicates that there is an issue with the syntax or structure of the code, preventing it from being successfully compiled into an executable file.

2. How do I know if I have a Fortran compile error?

If you are trying to compile a Fortran program and encounter an error message, then you have a Fortran compile error. The error message will usually provide information about the specific line of code where the error occurred, as well as the type of error.

3. Why am I getting a Fortran compile error?

There are many possible reasons for a Fortran compile error. Some common causes include syntax errors, missing or incorrect libraries, and incompatible compiler options. It is important to carefully review the error message and the code to determine the specific cause of the error.

4. How do I fix a Fortran compile error?

The process of fixing a Fortran compile error will depend on the specific error and the cause. In general, you can start by carefully reviewing the error message and the code to identify any syntax errors. You may also need to check for missing libraries or incompatible compiler options. If you are unable to resolve the error on your own, you may need to seek assistance from a more experienced Fortran programmer.

5. How can I prevent Fortran compile errors in the future?

The best way to prevent Fortran compile errors is to write well-structured and error-free code. This includes using proper syntax, following coding conventions, and thoroughly testing your code before attempting to compile it. It is also helpful to regularly review and debug your code to catch any potential errors before they become compile errors.

Similar threads

  • Programming and Computer Science
Replies
4
Views
619
  • Programming and Computer Science
Replies
12
Views
964
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
25K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
13K
  • Programming and Computer Science
Replies
26
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top