#include #include #include #include #include #include using namespace std; using namespace Eigen; int main( int argc, char **argv){ if(argc != 5){ cout << "Usage :\n"; cout << "\t Nx # of intervals ?\n"; cout << "\t Correlation length?\n"; cout << "\t Exponent?\n"; cout << "\t KL Truncation level?\n"; exit(0); } /* Read the problem paremater */ unsigned N = atoi(argv[1]); //# of spatial Cells double L = atof(argv[2]); //Correlation length double P = atof(argv[3]); //Exponent of the Covariance kernel unsigned T = atoi(argv[4]); //Truncature of the KL expansion /* Create a pseudo random number generator and a normal distribution */ std::default_random_engine generator; std::normal_distribution normal(0.0,1.0); double dx = 1./(double)(N); // Spatial step MatrixXd K(N,N); //Covariance matrix for(unsigned i=0; i Eig(K); //Decompose K MatrixXd Ev = Eig.eigenvectors()/sqrt(dx); //Retrieve eigenvectors (and scale them) VectorXd Lm = Eig.eigenvalues(); //Retrieve eigenvalues Lm.array() = Lm.array().abs(); //Move eigenvalues to their absolute value to ensure positivity even for close to zero value (round-off error) for(unsigned i=0; i