Beispiel #1
0
void
Serial(int m, int n)
{
	double	p_value1, p_value2, psim0, psim1, psim2, del1, del2;
	
	psim0 = psi2(m, n);
	psim1 = psi2(m-1, n);
	psim2 = psi2(m-2, n);
	del1 = psim0 - psim1;
	del2 = psim0 - 2.0*psim1 + psim2;
	p_value1 = cephes_igamc(pow(2, m-1)/2, del1/2.0);
	p_value2 = cephes_igamc(pow(2, m-2)/2, del2/2.0);
	
	fprintf(stats[TEST_SERIAL], "\t\t\t       SERIAL TEST\n");
	fprintf(stats[TEST_SERIAL], "\t\t---------------------------------------------\n");
	fprintf(stats[TEST_SERIAL], "\t\t COMPUTATIONAL INFORMATION:		  \n");
	fprintf(stats[TEST_SERIAL], "\t\t---------------------------------------------\n");
	fprintf(stats[TEST_SERIAL], "\t\t(a) Block length    (m) = %d\n", m);
	fprintf(stats[TEST_SERIAL], "\t\t(b) Sequence length (n) = %d\n", n);
	fprintf(stats[TEST_SERIAL], "\t\t(c) Psi_m               = %f\n", psim0);
	fprintf(stats[TEST_SERIAL], "\t\t(d) Psi_m-1             = %f\n", psim1);
	fprintf(stats[TEST_SERIAL], "\t\t(e) Psi_m-2             = %f\n", psim2);
	fprintf(stats[TEST_SERIAL], "\t\t(f) Del_1               = %f\n", del1);
	fprintf(stats[TEST_SERIAL], "\t\t(g) Del_2               = %f\n", del2);
	fprintf(stats[TEST_SERIAL], "\t\t---------------------------------------------\n");

	fprintf(stats[TEST_SERIAL], "%s\t\tp_value1 = %f\n", p_value1 < ALPHA ? "FAILURE" : "SUCCESS", p_value1);
	fprintf(results[TEST_SERIAL], "%f\n", p_value1);

	fprintf(stats[TEST_SERIAL], "%s\t\tp_value2 = %f\n\n", p_value2 < ALPHA ? "FAILURE" : "SUCCESS", p_value2);
	fprintf(results[TEST_SERIAL], "%f\n", p_value2);
}
Beispiel #2
0
int main(int argc, const char * argv[]) {
    // insert code here...
    
    PubSubImpl psi("psi1");
    PublishableString * s = new PublishableString("String Hello");
    PubSubImpl psi2("psi2");
    psi.publish(s);
    
    
    return 0;
}
// вектор b[i]
double psi_vector(int i,double x_p, double h_x)
{
	switch (i)
	{
	case 1: return psi1(x_p, h_x);
		break;
	case 2: return psi2(x_p, h_x);
		break;
	case 3: return psi3(x_p, h_x);
		break;
	case 4: return psi4(x_p, h_x);
		break;
	}
}
//матрица M[i][j]
double psi_matrix(int i, int j,double x_p, double h_x)
{
	switch (i)
	{
	case 1:
		switch (j)
		{
		case 1:return psi1(x_p, h_x)*psi1(x_p, h_x);break;
		case 2:return psi1(x_p, h_x)*psi2(x_p, h_x);break;
		case 3:return psi1(x_p, h_x)*psi3(x_p, h_x);break;
		case 4:return psi1(x_p, h_x)*psi4(x_p, h_x);break;
		}

	case 2:
		switch (j)
		{
		case 1:return psi2(x_p, h_x)*psi1(x_p, h_x);break;
		case 2:return psi2(x_p, h_x)*psi2(x_p, h_x);break;
		case 3:return psi2(x_p, h_x)*psi3(x_p, h_x);break;
		case 4:return psi2(x_p, h_x)*psi4(x_p, h_x);break;
		}
	case 3:
		switch (j)
		{
		case 1:return psi3(x_p, h_x)*psi1(x_p, h_x);break;
		case 2:return psi3(x_p, h_x)*psi2(x_p, h_x);break;
		case 3:return psi3(x_p, h_x)*psi3(x_p, h_x);break;
		case 4:return psi3(x_p, h_x)*psi4(x_p, h_x);break;
		}
	case 4:
		switch (j)
		{
		case 1:return psi4(x_p, h_x)*psi1(x_p, h_x);break;
		case 2:return psi4(x_p, h_x)*psi2(x_p, h_x);break;
		case 3:return psi4(x_p, h_x)*psi3(x_p, h_x);break;
		case 4:return psi4(x_p, h_x)*psi4(x_p, h_x);break;
		}
	}
}
int main() {
    const double L{10};  // computation window is [-L, +L] in both directions
    const double d_l{.1};
    const double d_t{0.02};
    const double xi0{1};
    const double si{1};
    const size_t t{500};

    const int N(1 + static_cast<int>(2 * L / d_l + 0.5));

    matXcd H = matXcd::Identity(N, N) * -2;

    H.topRightCorner(N - 1, N - 1) += matXcd::Identity(N - 1, N - 1);
    H.bottomLeftCorner(N - 1, N - 1) += matXcd::Identity(N - 1, N - 1);
    H *= -1. / pow(d_l, 2);
    H += Eigen::VectorXd::LinSpaced(N, -L, L).cwiseAbs2().cast<cd>().asDiagonal();

    // Anharmonizität
    // H += 1e-4 * Eigen::VectorXd::LinSpaced(N, -L, L).cwiseAbs2().cwiseAbs2().cast<cd>().asDiagonal();

    matXcd S_p = matXcd::Identity(N, N) + cd(0, 1) * 0.5 * d_t * H;
    matXcd S_n = matXcd::Identity(N, N) - cd(0, 1) * 0.5 * d_t * H;
    matXcd S = S_p.inverse() * S_n;

    VecXcd psi0 = Eigen::VectorXd::LinSpaced(N, -L, L)
                      .unaryExpr([xi0, si](double xi) { return exp(-pow(xi - xi0, 2) / (4 * si)); })
                      .cast<cd>()
                      .normalized();

    std::vector<VecXcd> psi(t, VecXcd(N));
    psi[0] = psi0;

    for (auto it = psi.begin() + 1; it != psi.end(); ++it) *it = S * *(it - 1);

    boost::multi_array<float, 2> psi2(boost::extents[N][t]);
    for (long i = 0; i < N; i++) {
        for (long j = 0; j < static_cast<long>(t); j++) {
            psi2[i][j] = static_cast<float>(norm(psi[static_cast<size_t>(j)][i]) / d_l);
        }
    }

    //––– plotting with python ––––––––––––––––––––––––––––––––––––––––––––––––
    namespace py = boost::python;
    namespace np = boost::numpy;

    try {
        Py_Initialize();
        np::initialize();

        // Retrieve the main module's namespace
        py::object global(py::import("__main__").attr("__dict__"));

        // Import neccessary modules
        py::exec("from __future__ import division \n"
                 "print 'Hello from Python!' \n"
                 "import numpy as np \n",
                 global, global);

        // Import variables and vectors
        global["N"] = N;
        global["t"] = t;
        global["d_l"] = d_l;
        global["d_t"] = d_t;

        py::tuple strides_1 =
            static_cast<py::tuple>(py::eval("np.ndarray((N, t), np.float32).strides", global, global));

        global["psi2"] =
            np::from_data(psi2.data(), np::dtype::get_builtin<float>(), py::make_tuple(N, t), strides_1, py::object());

        // Launch some function in Python
        py::exec_file("1_plots.py", global, global);
    } catch (const py::error_already_set &) {
        std::cout << extractPythonException() << std::endl;
        exit(EXIT_FAILURE);
    }

    return 0;
}