Nan in Pascal when working with values from an array

0

I am developing a program in Pascal that takes a matrix and assigns to each box the average of the 4 adjacent quasi-squares during n repetitions.

for contador:= 1 to itera do
begin
    for i := 0 to width-1 do 
    begin


        for z := 0 to height-1 do
        begin
        if(mapnew[i][z].modifi) then

            mapnew[i][z].pot := ( map[i+1][z].pot+map[i][z+1].pot+map[i-1][z].pot+map[i][z-1].pot)/4;

        end;
    end;
    map:= mapnew;
end; 

The problem is that when I execute it and print the matrix with which I work, I get the modified Nan values. I know it's not a number, but I'd like it to show the result but I do not know how to modify it.

    
asked by PABLO FERNANDEZ 19.04.2018 в 12:52
source

1 answer

0

Could you solve the problem? Have you considered what happens at the edges of the matrix?

If the line:

if(mapnew[i][z].modifi) then

It was created in order to read the inside of the matrix without taking the edges so as not to read out when i or z equals 0 or are of the maximum value. This will result in the edge not being modified. In the first pass, the resulting value will be used to initialize mapnew[borde][borde].pot and successive iterations will take it as a reference value.

This is due to the line:

map:= mapnew;

If you still have the pending challenge and can share a bit more of the code, we should be able to solve it. It would also be good to give an example of the expected result, so as to take into account where we take the values when we are at the point 0,0 or Max , Max of the matrix.

    
answered by 25.05.2018 в 14:35