</table>
<hr>
<pre>/***************************************************************************
 * $Id: inverse2.cpp,v 1.7 2004/02/27 17:57:16 prakash Exp $
 *
 * An example of the inverse iteration method with a complex matrix.
 *
 * Copyright (C) 2001-2003 by Prakash Dayal &lt;prakash@comp-phys.org&gt;
 *                            Matthias Troyer &lt;troyer@comp-phys.org&gt;
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 **************************************************************************/
 
#include &quot;solver.h&quot;

#include &lt;ietl/inverse.h&gt;
#include &lt;ietl/interface/ublas.h&gt;
#include &lt;ietl/vectorspace.h&gt;
#include &lt;ietl/iteration.h&gt;
#include &lt;boost/numeric/ublas/matrix.hpp&gt;
#include &lt;boost/numeric/ublas/io.hpp&gt;
#include &lt;boost/random.hpp&gt;
#include &lt;iostream&gt;

typedef boost::numeric::ublas::matrix&lt;std::complex&lt;double&gt;, boost::numeric::ublas::column_major&gt; Matrix; 
typedef boost::numeric::ublas::vector&lt;std::complex&lt;double&gt; &gt; Vector;
typedef ietl::vectorspace&lt;Vector&gt; Vecspace;
typedef boost::lagged_fibonacci607 Gen;

int main()
{
   std::cout &lt;&lt; &quot;Inverse Iteration v0.11\n&quot;;
   std::cout &lt;&lt; &quot;-----------------------------------------------\n\n&quot;;

   // Dimension of Matrix
   int n = 3;
   
   // Absolute Error Tolerance
   double abs_tol = std::numeric_limits&lt;double&gt;::epsilon();
   
   // Relative Error Tolerance
   double rel_tol = 5. * std::numeric_limits&lt;double&gt;::epsilon();
   
   // Maximum Iterations
   int max_iter = 20;

   // Construct the Iteration Object
   ietl::basic_iteration&lt;double&gt; iter(max_iter, rel_tol, abs_tol);

   // Sigma (where we suppose the eigenvalue to be)
   double sigma = -5; // EV are: -5.21; 2.36; 5.85

   // Initialize Matrix
   Matrix mat(n,n);
   mat(0,0) = std::complex&lt;double&gt;(2,0);   
   mat(0,1) = std::complex&lt;double&gt;(2,1);   
   mat(0,2) = std::complex&lt;double&gt;(0,-2);
   mat(1,0) = std::complex&lt;double&gt;(2,-1);  
   mat(1,1) = std::complex&lt;double&gt;(-3,0);  
   mat(1,2) = std::complex&lt;double&gt;(-1,3);
   mat(2,0) = std::complex&lt;double&gt;(0,2);   
   mat(2,1) = std::complex&lt;double&gt;(-1,-3); 
   mat(2,2) = std::complex&lt;double&gt;(4,0);

   // Create Vectorspace      
   Vecspace vec(n);
   
   // Create Generator for the starting vector
   Gen mygen;
   
   // Create the solver
   Solver&lt;Matrix, Vector&gt; mysolver;
   
   // Show the Matrix
   std::cout &lt;&lt; mat &lt;&lt; std::endl;

   // Calculate the eigenvalue and the eigenvector
   std::pair&lt;double, Vector&gt; result = ietl::inverse(mat, mygen, mysolver, iter, sigma, vec);
   
   // Print out the obtained results
   std::cout.precision(20);
   std::cout &lt;&lt; &quot;Eigenvalue: &quot;&lt;&lt; result.first &lt;&lt; std::endl;
   std::cout &lt;&lt; &quot;Eigenvector: &quot;&lt;&lt; result.second &lt;&lt; std::endl;

   // Calculate the error as the norm of (Av-theta*v)
   Vector error = ietl::new_vector(vec);
   std::cout &lt;&lt; mat &lt;&lt; std::endl &lt;&lt; result.second &lt;&lt; std::endl;
   ietl::mult(mat,result.second,error);
   std::cout &lt;&lt; error;
   error -= result.first*result.second;
   std::cout &lt;&lt; error;
   std::cout &lt;&lt; &quot;error: &quot; &lt;&lt; ietl::two_norm(error) &lt;&lt; std::endl;
   
   return 0;
}
</pre>
