Why Does My Fortran Code Give an Unclassifiable Statement Error?

Click For Summary

Discussion Overview

The discussion revolves around a Fortran code error related to an "unclassifiable statement" message encountered while implementing Euler's method for numerical approximation. Participants analyze the code and suggest potential corrections and clarifications regarding syntax and programming conventions.

Discussion Character

  • Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • One participant reports an error message indicating an unclassifiable statement in the function definition of their Fortran code.
  • Another participant suggests that the error arises from the omission of the multiplication operator "*", proposing the corrected line as "fun=(c)*(1-c)/(d+2)".
  • A later reply emphasizes the importance of using explicit multiplication operators in programming languages, contrasting it with mathematical notation where juxtaposition can imply multiplication.
  • Additional clarification is provided regarding the use of the "=" operator in programming for assignment versus its use in mathematics for equality.

Areas of Agreement / Disagreement

Participants generally agree on the cause of the error related to the missing multiplication operator, but the discussion includes varying levels of detail and additional insights about programming conventions.

Contextual Notes

The discussion highlights common pitfalls for new programming students, particularly in distinguishing between mathematical notation and programming syntax. There is also mention of differences in equality operators between mathematics and programming languages.

gabforse
Messages
1
Reaction score
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
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)".
 
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
 
@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).
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
28K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
14K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 26 ·
Replies
26
Views
4K
  • · Replies 59 ·
2
Replies
59
Views
12K