0

I'm generating a module that calculates the Legendre polynomials but once I reach to ˋP4(x)ˋ I start getting 0 as output.

For instance ˋP4(x) = 1/8 * (35x^4 - 30x^2 +3)ˋ

So I've decided to make the following program in order to check any possible mistake.

real (kind = 8) :: x,y
integer :: i

y = 0.0, x = -1.0

do i = 1, 30

y = ((1/8)*((35*(x**4))-(30*(x**2))+3)

write (6,*) y

cont = cont + 0.066

end do

The output of this program is always the same 0.000000

Surprisingly, it shows the changes of sign but it still displays -0.000000.

Pol
  • 1
  • How does the loop variable `i` influence the output of `y` at each stage? I don't understand your example code. – Ross Nov 22 '17 at 18:16
  • 2
    Also, the reason you get `0` is because `1/8` evaluates to `0` due to integer division. – Ross Nov 22 '17 at 18:17
  • In reference to @Ross comment, see [here](http://www.fortran90.org/src/gotchas.html#floating-point-numbers-gotcha) for some gotchas in regards to integer/floating point literal declarations. – pstrjds Nov 22 '17 at 18:20
  • You appear to be a beginner. It is not a problem here, but do not learn `real(kind=8)` whoever learns you that way. It us bad and not portable. Declare a constant `integer, parameter :: rp=kind(1.d0)` and then use `real(rp)`. It is even shorter. – Vladimir F Героям слава Nov 22 '17 at 18:32

0 Answers0