2D discrete Laplacian (del2) in C ++

I am trying to figure out how to port del2 () function to matlab in C ++.

I have a couple of masks that I work with, those are also zeros, so I wrote the code liket his:

for(size_t i = 1 ; i < nmax-1 ; i++)

{
    for(size_t j = 1 ; j < nmax-1 ; j++)

    {
        transmask[i*nmax+j] = .25*(posmask[(i+1)*nmax + j]+posmask[(i-1)*nmax+j]+posmask[i*nmax+(j+1)]+posmask[i*nmax+(j-1)]);

    }
}

to calculate the internal points of the Laplacians. I think, according to some information in "doc del2" in matlab, the boundary conditions just use the available information to calculate, right? I think I just need to write cases for the boundary conditions in i, j = 0 and nmax

However, I would have thought that these values ​​from the code I posted here would be correct for the internal points as they are, but it looks like the results of del2 are different!

I broke through the source del2, and I think that I am missing the Matlab wizard to figure out what happens with some code to calculate the interior

+5
3

, :

transmask[i*nmax+j] = .25*(posmask[(i+1)*nmax + j]+posmask[(i-1)*nmax+j]+posmask[i*nmax+(j+1)]+posmask[i*nmax+(j-1)]);  

.

(I (i + 1, j) + (i-1, j) + (i, j + 1) + (i, j-1))/4

, , ( , 1):

(- 4 * (i, j) + (i + 1, j) + (i-1, j) + (i, j + 1) + (i, j-1))

, , , 4. , x y .

: , /4, Matlab - ( ).

+3

del2 edit del2 type del2. , del2 .

+5

I think using the Matlab compiler you can convert m-code to C-code. Have you tried this?

I found this link where another label for conversion to C is explained.

http://www.kluid.com/mlib/viewtopic.php?t=337

Good luck.

+3
source

All Articles