@lastchance nvm actually you're right, when I change my index in the for loop to ny I get the same dv outside of the for loop. Now, what I want is to have the correct size(ny+1 * ny+1). I tried using dv.resize(ny+1,ny+1); and replicate as well and both give error messages and do not work. What is the correct approach here?
oh well, you're right!
Allow me to ask few stupid question. I guess, I was indexing j + ny*i which in my head made sense and was working fine to this point so idk why is it wrong here. And when I index dv(j,i) I get the exact correct results to my MATLAB code vs (i,j) which returns few signs off.
Finally Thanks A LOT!
The matrix has ny+1 rows and columns so to access column j row i you'd need to say dv(j + (ny + 1)*i). Notice that Eigen does use a column-major storage order hence why you might have got the indices backward, especially since C++ programmers use row-major order by convention.
oh yeah this is it, I have completely missed this. Also, I keep forgetting about Eigen uses column-major storage. I will need to be more careful moving forward since I am switching to Eigen now. Thanks again btw.