Fortran Fortran 95 Help ( Compiling errors)

  • Thread starter Thread starter shadow1768
  • Start date Start date
  • Tags Tags
    Errors Fortran
AI Thread Summary
The discussion revolves around troubleshooting a Fortran 95 program designed to calculate the sine of an angle using an infinite series. The user initially encounters compilation errors due to missing multiplication operators in expressions involving factorial calculations. Specifically, the expressions for calculating factorial and the series terms were incorrectly written, leading to syntax errors. After resolving these issues by adding the necessary multiplication operators, the user successfully compiles the program but faces challenges with correctly implementing the factorial calculation within the loop. The conversation suggests that for further coding assistance, the user should consider posting in the homework help section or the Engineering branch of the forum.
shadow1768
Messages
2
Reaction score
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
Took me a minute too...

2n needs to be 2*n
 
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.
 
I think either place would be fine: here or in the Engineering branch of the homework help forum. Start a new thread, though.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
25
Views
3K
Replies
4
Views
2K
Replies
16
Views
2K
Replies
8
Views
2K
Replies
5
Views
5K
Replies
19
Views
2K
Back
Top