-2

I have this program that I wrote trying to test out if I could define a user inputted function then get Fortran to do summation with it. This is what I did.

program test

real :: a,b,n,k,sum

integer, intent(out) :: func
print *, 'what are the values of a b n k?'
read *, a,b,n,k
print *, 'what is the function?'
read *, func
sum = 0

DO I= 1, 6
    x = ((A)+I * ((b-a)/(n)))
        sum = sum + func
END DO


print *, sum 

end program test

The compiler said this in return:

sh-4.3$ gfortran -std=f95 *.f95 -o main                                                                                                                                               
Newfile.f95:5:28:                                                                                                                                                                     

 integer, intent(out) :: func                                                                                                                                                         
                            1                                                                                                                                                         
Error: Symbol at (1) is not a DUMMY variable 

Any ideas?

p.patel
  • 11
  • 1
    Let me get this straight: You want the user to enter an arbitrary function, say: `f(x) = 1/x`, and then use that function to calculate any values? Good luck with that. You'll have to read it in as a string, then analyse the string to assemble the appropriate calculations. That's a major undertaking. – chw21 Sep 15 '16 at 01:40
  • I want to use that function thats entered by the user to integrate it, using lower and upper limit with a certain amount of divisions all using the trapezoid rule (lower = a, upper = b, divisons = n) – p.patel Sep 16 '16 at 02:58

1 Answers1

0
   integer, intent(out) :: func

can be used to declare a procedure argument, but you placed it into the main program.

The intent(out) makes no sense there.

A different issue is that it is not clear what the function should be in your program.

  • how do I fix this so that i can accomplish f(x)= x**2+1 and then use that to do f(((A)+I * ((b-a)/(n)))? my ultimate goal is to write a program which can accomplish integration using the trapezoidal rule, and this is just a peice of which I will use to accomplish that goal – p.patel Sep 14 '16 at 21:12
  • 1
    That is too much to ask for one question. At this stage the answer is you must study more basics of Fortran. For start you should use a fixed function, not ask the user for it. – Vladimir F Героям слава Sep 14 '16 at 21:15
  • @p.patel There are examples of similar programs on this site like http://stackoverflow.com/questions/19716536/problems-with-the-trapezoidal-rule you can look at them and try to understand them. Don't just blindly copy something. – Vladimir F Героям слава Sep 14 '16 at 21:17