Fortran 95 Help ( Compiling errors)

In summary, the user is having trouble with adding the functions and the compiler is giving them errors.
  • #1
shadow1768
2
0
Hello all, I'm kinda stuck with this fortran 95 program I have to write. It is an Infinite Series of SIN.

IMPLICIT NONE
!
! Data Dictionary
REAL :: x ! Measurement of angle in degrees
REAL :: result ! facilitates addition of the functions
REAL :: f_x ! function defining the series
REAL :: rad_x ! Radians equivalent of x
REAL :: int_value ! Intrinsic function value of sin
REAL, PARAMETER :: PI = 3.141593 ! universal ratio of circle's diameter
INTEGER :: n ! Counter
INTEGER :: fac ! factorial calculation

! User Input of X
WRITE (*,*) 'Input degrees'
READ (*,*) x
!
! Convert to Radians
rad_x = x *(PI/180)
!
! Defining Base values for addition of LOOPs
result = 0.0
fac = 0
!
! Start of DO LOOP
DO n = 1, 10
fac = (2n - 1) *n
f_x = (-1.0**(n-1))*((rad_x**(2n-1))/(fac))
result = f_x + result
END DO
!
! Calcualte INtrinsic value of SIN
int_value = SIN(rad_x)
!
! Display information
WRITE (*,*) 'Intrinsic SIN function value', int_value
WRITE (*,*) 'Calculated value of SIN', result
!
! Finish Up
END PROGRAM infinite_series

And I receive the following errors from the compiler

In file infinite.f95:35

fac = (2n - 1) *n
1
Error: Expected a right parenthesis in expression at (1)
In file infinite.f95:36

f_x = (-1.0**(n-1))*((rad_x**(2n-1))/(fac))
1
Error: Expected a right parenthesis in expression at (1)

The "1" is actually under the 2 in (2n-1) but it won't stay put in the post.

I'm trying to compile to see if the program even works but I need to get past this first. Thank you for any help

After about a couple hours of racking my brain I discovered I was missing the multiply operator between the 2 and n. fail

Now the program compiles but I'm having issues with getting the factorial part of the work properly. I can't seem to figure out how to get it to multiply properly within the DO loop. If I separate the two, I can get the factorial to work, but I will not get the equation to work. argh!
 
Last edited:
Technology news on Phys.org
  • #2
Took me a minute too...

2n needs to be 2*n
 
  • #3
Indeed. Quick question, now if I need help coding, do I make a new post in the homework help section or something or another? I can't get the factorials right.
 
  • #4
I think either place would be fine: here or in the Engineering branch of the homework help forum. Start a new thread, though.
 

1. What is Fortran 95?

Fortran 95 is a high-level programming language used primarily for scientific and engineering applications. It is an extension of the original Fortran language and includes features such as modules, pointers, and recursion.

2. How do I compile Fortran 95 code?

To compile Fortran 95 code, you will need a Fortran compiler installed on your computer. Popular options include GNU Fortran (gfortran) and Intel Fortran (ifort). Once you have a compiler installed, you can use it to compile your code into an executable file that can be run on your computer.

3. What are common compiling errors in Fortran 95?

Some common compiling errors in Fortran 95 include syntax errors, undefined variables, and mismatched data types. These errors can typically be resolved by carefully checking your code for mistakes and making sure all variables are properly declared and referenced.

4. How can I troubleshoot compiling errors in Fortran 95?

If you encounter a compiling error in Fortran 95, the first step is to carefully read the error message to determine the source of the problem. You can also try using a debugger or code editor with a built-in compiler to help identify and fix errors. Additionally, searching online forums and consulting with other Fortran programmers can provide helpful insights and solutions.

5. Are there any resources available for learning Fortran 95?

Yes, there are many resources available for learning Fortran 95. Some popular options include online tutorials, textbooks, and online courses. Additionally, many universities and colleges offer courses on Fortran programming. It can also be helpful to join online forums or attend Fortran conferences to connect with other programmers and learn from their experiences.

Similar threads

  • Programming and Computer Science
Replies
21
Views
309
  • Programming and Computer Science
Replies
4
Views
625
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
Back
Top