1

I'm trying to write an array of this kind

Coefficients phi(m,r) and dphi(m,r) are functions, where cheby and dcheby are Chebyshev polynomials and its derivates respectively,

  Real(kind=8) FUNCTION phi(m,r)
  implicit none 
  integer m
  real(kind=8) r
  real(kind=8) cheby

  if(mod(m,2).eq.0) then
  phi = cheby(m+2,r)-cheby(0,r)
  else if (mod(m,2).eq.1) then 
  phi = cheby(m+2,r) - cheby(1,r)
  end if
  end FUNCTION phi

  Real(kind=8) FUNCTION dphi(m,r)
  implicit none 
   integer m
   real(kind=8) r
   real(kind=8) dcheby  
   if(mod(m,2).eq.0) then
   dphi = dcheby(m+2,r) - dcheby(0,r)
   else if (mod(m,2).eq.1) then 
   dphi = dcheby(m+2,r) - dcheby(1,r)
   end if 
  end FUNCTION dphi

so first i define g and then i used 2nd order- simpson's rule to integrate

Real(kind=8) FUNCTION g(j,i,r)
       implicit none 
       integer i,j
       real(kind=8) r
       real(kind=8) dphi, phi
       real(kind=8) lambda

       g = -dphi(j,r)*dphi(i,r) + lambda*phi(j,r)*phi(i,r)

end FUNCTION g 


Real(kind=8) FUNCTION integrate(j,i)
   implicit none 
   integer i, j
   real(kind=8) g
   Real(kind=8) xmax, xmin
   xmax = 1.0d0
   xmin = -1.0d0 

   integrate =(( xmax -  xmin)/6)*(g(j,i,xmin) +4*g(j,i,0.0d0) + g(j,i,xmax)) 

end FUNCTION integrate

However i don't know how write the matrix, i wrote that

 do i=0,N
     do l=0,N
       A(i,l) = integrate(j,i)
     end do
 end do 

but, when I compiled A= NaN

PCat27
  • 33
  • 1
  • 7
  • 1
    Can you add your functions `phi` and `dphi` to make the example complete? – kabanus Sep 29 '18 at 17:02
  • So now we have to find `cheby` and `dcheby`? – albert Sep 29 '18 at 17:33
  • @albert means that for a proper question so we can help, we need a complete, compilable piece of code. – kabanus Sep 29 '18 at 17:36
  • So, I've used a program with cheby and dcheby, however I'll upload complete code. – PCat27 Sep 29 '18 at 18:14
  • @kabanus Here is complete program https://github.com/dayacaca/Computational_Physics/blob/master/M%C3%A9todos%20Espectrales/Galerkin/Helmholtz/Helmholtz.f90 – PCat27 Sep 29 '18 at 18:33
  • @kabanus indeed that is what I meant, maybe a bit cynic. After the question / comment about `phi` and `dphi` the unknown functions `cheby` and `dcheby` surfaced. – albert Sep 29 '18 at 20:26
  • Do not use kind=8 everywhere, it is just hurting my eyes. See https://stackoverflow.com/questions/838310/fortran-90-kind-parameter Try toi ue some meaningful indentation to make the structure apparent. – Vladimir F Героям слава Sep 29 '18 at 20:51
  • you should reduce your problem to a [mcve] so we could help you. As it is presented now, you declare `real(kind=8) cheby`. This is a real-type scalar, not a local function. Please, provide a testable code. – Rodrigo Rodrigues Sep 30 '18 at 17:34
  • I recommend that you break up the problem in smaller parts. The nan value that you obtain follows from a loop that calls the polynials behind the integration routine. First check that you polynomial functions and derivatives give the expected result, then test out the integration routine at specified values of the arguments, and finally you can try to build the full program. – Pierre de Buyl Oct 01 '18 at 07:44

0 Answers0