0

I am using Microsoft Visual Studio with Intel Fortran and totally new to this coding platform. If my question is not worthy enough to put here, I ask for the apology in advance but I really need the solution to this problem. I am needed to integrate a large number of trigonometric expressions (approx. 4860). I am using the QUADPACK library and following code:

program integral

  real ( kind = 4 ), parameter :: a = 0.0E+00
  real ( kind = 4 ) abserr
  real ( kind = 4 ) b,x
  real ( kind = 4 ), parameter :: epsabs = 0.0E+00
  real ( kind = 4 ), parameter :: epsrel = 0.001E+00
  real ( kind = 4 ), external :: f2
  integer ( kind = 4 ) ier
  integer ( kind = 4 ), parameter :: key = 6
  integer ( kind = 4 ) neval
  real ( kind = 4 ), parameter :: r4_pi = 3.141592653589793E+00
  real ( kind = 4 ) result1
  real ( kind = 4 ), parameter :: true = 0.06278740E+00

  b = r4_pi

  call qag ( f2, a, b, epsabs, epsrel, key, result1, abserr, neval, ier )

  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) 'QAG_TEST'
  write ( *, '(a)' ) '  Test QAG'
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  Integrand is COS(100*SIN(X))'
  write ( *, '(a,g14.6)' ) '  Integral left endpoint A =    ', a
  write ( *, '(a,g14.6)' ) '  Integral right endpoint B =   ', b
  write ( *, '(a,g14.6)' ) '  Exact integral is             ', true
  write ( *, '(a,g14.6)' ) '  Estimated integral is         ', result1
  write ( *, '(a,g14.6)' ) '  Estimated integral error =    ', abserr
  write ( *, '(a,g14.6)' ) '  Exact integral error =        ', true - result
  write ( *, '(a,i8)' ) '  Number of function evaluations, NEVAL = ', neval
  write ( *, '(a,i8)' ) '  Error return code IER = ', ier

end program integral

function f2(x)
  implicit none

  real ( kind = 4 ) f2
  real ( kind = 4 ) x
  f2=COS(100*SIN(X))
end function

From the above code, I can easily find the integral of a single expression. But in my case, I have an array (18*270) containing all the elements as a mathematical expression. I want to call them one by one and integrate them. Please suggest me how to deal with it. Thank you.

ayada30
  • 1
  • 1
  • How doe the array with the expressions look like? How does an example expression look like? Are they strings or function pointer or what are they? Or is it a text file? – Vladimir F Героям слава May 07 '20 at 06:19
  • It’s a text file exported from Mathematica. @VladimirF – ayada30 May 07 '20 at 06:28
  • Please show an example. Are you able to parse those expressions? – Vladimir F Героям слава May 07 '20 at 06:41
  • KNL3(6,270)=-4.0807374705034445e13*Sin(7*t)*U1(166)**2 - 8.161474941006889e13*Cos(t)*Sin(7*t)*U1(166)*U1(167). It is not possible to put the complete expression here because of the characters limit in the comment box so I showed you 2 terms. All the remaining terms have the same format as above. Vector U1 is known and the expression should be integrated w.r.t t from 0 to 2*Pi. I have no clue about parsing. If parsing is the only solution, I can give a try to learn from web. @VladimirF – ayada30 May 07 '20 at 06:59
  • Check https://stackoverflow.com/questions/7326828/passing-strings-for-execution-in-fortran-subroutines https://stackoverflow.com/questions/40686838/how-does-one-insert-fortran-code-from-an-external-file-into-a-separate-code?noredirect=1&lq=1 – Vladimir F Героям слава May 07 '20 at 07:08
  • Firstly please learn why real( 4 ) is very bad practice - see https://stackoverflow.com/questions/838310/fortran-90-kind-parameter. Secondly can you tell us what the interface to qag is? Is thre an interface to quadpack that uses procedure pointers? If you can't do this can you parameterise the functions, and pass the parameters as arguments to a single function? If not I'm afraid you're going to have to parse the functional form, unless I am missing something – Ian Bush May 07 '20 at 07:08
  • Don't put important explanatory material in comments, edit your question. It's very difficult to 'grok' an expression squeezed into a comment. Especially so, as you rightly write *It is not possible to put the complete expression here because of the characters limit in the comment box* – High Performance Mark May 07 '20 at 09:24
  • I am very puzzled here: You have a file which is exported by Mathematica. Why don't you just use Mathematica to compute all the integrals? – kvantour May 07 '20 at 09:44
  • I'm puzzled why you reinserted think the irrelevant tags I took out. Whatever this is it certainly isn't Fortran77, it is standard, modern Fortran, thus fortran90 and intel are irrelevant as well. – Ian Bush May 07 '20 at 14:48

0 Answers0