title: How to generate a matrix in matlab with the next values?
body: <p>I have the next question, how to build a matrix with specific values knowing that the size of the matrix is NxN.</p>
  
  <p><a href="http://i.stack.imgur.com/GrUfD.png" rel="nofollow">Here is my question</a></p>
  
  <p>I've being trying with the next code:</p>
  
  <pre><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);
  </code></pre>
  
  <p>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?</p>