Nonsense error in FORTRAN

Hello, I've been trying to set up a code for fortran, it's about integration, the problem comes when I try to compile the program, the log shows 2 errors: "Error: Expected a right parenthesis in expression " 2 times, and only in 1 shows the line in which it's apparently located (32), I'm going crazy cause i can't find the problem, does anyone know what's wrong?, the code is:

program main
  implicit none
  integer :: n,i,k
  real*8 :: a,b,x,trapecio,s,suma1,suma2,x2,formula1,formula2,eps,div,h

  !variables
  n=3
  a=0d8
  b=4d8


  !calculate the additions 1 a n-1 y 2 a n-2

  suma1=0d0
  suma2=0d0
  do n=3,300,2*n
   h=(b-a)/dble(n)

        do i=1,n-1,2
            x=a+dble(i)*h
            formula1= 1/(1+(x^2))
            suma1=  suma1 + formula1
        end do

        do k= 2,n-2,2
            x2=a+dble(k)*h
            formula2 =1/(1 + (x2^2)
            suma2= suma2+ formula2
        end do

     trapecio= h/3* &
     (1+ 4*suma1 + 2*suma2 + 1(1/n^2))
     div= trapecio/(trapecio/2)
            if (div < 1d-6) then
                exit
            end if

    write(*,*), trapecio
   end do
  end

Show the compilation command including all error messages. One error is here:

            formula2 =1/(1 + (x2^2)

For the rest the messages might help.

2 Likes

I've corrected the error you indicated before and now still appearing the same errors but doesn't show the line, the build log is:

-------------- Build: Debug in examen ejercicio2 (compiler: GNU Fortran Compiler)---------------

mingw32-gfortran.exe -Jobj\Debug\ -Wall  -g     -c "D:\Users\Luis Carlos Dorado\Desktop\examen ejercicio2\main.f95" -o obj\Debug\main.o
mingw32-gfortran.exe  -o "bin\Debug\examen ejercicio2.exe" obj\Debug\main.o   
D:\Users\Luis Carlos Dorado\Desktop\examen ejercicio2\main.f95:21:29: Error: Expected a right parenthesis in expression at (1)
D:\Users\Luis Carlos Dorado\Desktop\examen ejercicio2\main.f95:27:32: Error: Expected a right parenthesis in expression at (1)
  D:\Users\Luis Carlos Dorado\Desktop\examen ejercicio2\main.f95:32:31: Error: Expected a right parenthesis in expression at (1)

EDIT: I messed up with the exponentials so hard, thank you so much for your help sir!

My FORTRAN days are looooooong gone, but two of the three "error coordinates" indicate the complier might not be happy with the ^ for exponentiation. I faintly remember it being ** in those old days. Sure you got no syntax gobbledigook?

2 Likes
(1+ 4*suma1 + 2*suma2 + 1(1/n^2))

Should there be an operator between 1 and (1/n^2)

2 Likes

You remember it well hahaha I messed up with the exponentials. I know it's an old language that's barely used but in my University they make me use it in first grade.

And yes, I corrected that too

Thank you so much for your help, finally it compiled :b: