I'm a Fortran 77 learner, I'm new so don'n know much about Fortran. Our professor gave us a homework. We suppose to write a program that calculates cos(x**2). It has a Taylor expansion, so I tried to write some things but It gave me this error:
term = term*((-1)**i)*x**2*i)/fac(2*i) 1
Error: Unclassifiable statement at (1)
The hole program is:
PROGRAM COSX_SQUARE
IMPLICIT NONE
INTEGER x, n, i
REAL partial_sum, term
20 PRINT*, 'INPUT THE DEGREE'
READ*, x
x = x*180/3.1415
PRINT*, 'INPUT THE CORRECTION VALUE '
PRINT*, 'AS A NATURAL NUMBER'
READ*, n
i= -1
term = 1
partial_sum = term
10 i=i+1
term = term*((-1)**i)*x**2*i)/fac(2*i)
partial_sum = partial_sum + term
IF (i .LT. n) THEN
GO TO 10
ELSE
PRINT*, 'COS', x, 'SQUARE IS = ', partial_sum
END IF
GO TO 20
END
Where am I mistaking? And will this program work well? Thanks in advance.
You are missing one bracket in your expression!
It should probably read:
term = term*(((-1)**i)*x**2*i)/fac(2*i)