title: Runtime error in C++ with eigen library, any suggestions?
body: <p>I am new to C++ and eigen library. I am trying to code some simple stuff, but do not know where I am going wrong. Here is my code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;Eigen\Dense&gt;
  #include&lt;cmath&gt;
  #include&lt;fstream&gt;
  
    using namespace std;
    using namespace Eigen;
  
    int main (int argc, char* argv[])
    {
        int n = 200;
  
        Matrix&lt;double, Dynamic,1&gt; u_n;
        u_n.setZero(n,1);
  
        Matrix&lt;double, Dynamic,1&gt; u_n_minus_one;
        u_n_minus_one.setZero(n,1);
  
        Matrix&lt;double, Dynamic,1&gt; u_n_plus_one;
        u_n_plus_one.setZero(n,1);
  
        std::ofstream fileWriter ("Values.txt");
        assert(fileWriter.is_open());
  
        float r=2;
        float F=100;
  
        for (int t=0;t&lt;=5;t=t+1)
        {
  
  
                  u_n_plus_one (0,0) =0;
  //source of error
                  u_n_plus_one.block(1,0,n-1,0) = pow(r,2)*( u_n.block(1,0,n-2,0)+ u_n.block(3,0,n,0)) + 2*(1-pow(r,2))*u_n.block(1,0,n-1,0)-u_n_minus_one.block(1,0,n-1,0);
  //source of error
                  u_n_plus_one (floor(n/2),0)=F;
                  u_n_plus_one (n-1,0) =0 ;    //corrected from (n,0) to (n-1,0)
  
  
      u_n_minus_one = u_n ;
      u_n = u_n_plus_one ;
  
      //writing values to file
      if (remainder(t, 10) == 0)
      {
          fileWriter&lt;&lt;u_n.transpose()&lt;&lt;std::endl;
      }
  
     }
  
        fileWriter.close();
    }
  </code></pre>
  
  <p>I am trying to declare a few matrices (though they are vectors). Then I am doing operations on blocks of matrices, and finally writing the results to the file. I did not get any compile time error, but program crashes during run. </p>
  
  <p>I tried debugging the code and  the error seem to lie within <em>//source of error</em> statements. Can someone help me with this?</p>