I have the next question, how to build a matrix with specific values knowing that the size of the matrix is NxN.
I've being trying with the next code:
a = (1+2*Du*dt/dx^2);
b = -Du*dt/dx^2;
main = a*sparse(ones(Nx,1));
off = b*sparse(ones(Nx-1,1));
Bu = diag(main) + diag(off,1) + diag(off,-1);
But as you can see there is not the needed value in (1,1) and (N,N), so how can I build this specific matrices? How would be the code for this in MATLAB?