Beispiel #1
0
void solve(){
	double eps1 = 1e-9, eps2 = 1e-10, h = 0.01;
	double x = 0, b = 10;
	double y_0[N] = {1, 1, 1}, y_1[N], y_2[N];
	for(int i = 0; i < N; i++){
		y_1[i] = y_0[i];
		y_2[i] = y_0[i];
	}

	print(y_1, x, h);
	while(x < b){
		if(x + h > b)
			h = b - x ;
		newStep(x, y_1, h);
		newStep(x, y_2, h / 2);
		newStep(x + h / 2, y_2, h / 2);
		x += h;
		print(y_1, x, h);


		double err = 0;
		for(int j = 0; j < N; j++)
			err += (y_1[j] - y_2[j]) * (y_1[j] - y_2[j]);
		err = sqrt(err);
		for(int j = 0; j < N; j++)
			y_2[j] = y_1[j];
		
		if(err > eps1)
			h /= 2;
		else if(err < eps2)
			h *= 2;	
	}
	//fprintf(stderr, "%e\n", fabs(y_1[2] - fReal(y_1, b, 2)));
}
Beispiel #2
0
Datei: 4.cpp Projekt: filaPro/my
void solve(double h){
	double eps1 = 1e-5, eps2 = 1e-15;//, h = 0.1;
	double x = 0, b = 1, _h = h;
	double y_0[N] = {1}, y_1[N], y_2[N];
	for(int i = 0; i < N; i++){
		y_1[i] = y_0[i];
		y_2[i] = y_0[i];
	}

	//print(y_1, x, h);
	while(x < b){

		newStep(x, y_1, h);
		newStep(x, y_2, h / 2);
		newStep(x + h / 2, y_2, h / 2);
		x += h;
		print(y_1, x, h);
                  
		if(x + h > b)
			h = b - x ;
		double err = 0;
		for(int j = 0; j < N; j++)
			err += (y_1[j] - y_2[j]) * (y_1[j] - y_2[j]);
		err = sqrt(err);
		for(int j = 0; j < N; j++)
			y_2[j] = y_1[j];
		
		if(err > eps1)
			h /= 2;
		else if(err < eps2)
			h *= 2;
	}
	/*double err = 0;
	for(int j = 0; j < N; j++){
		err += (y_1[j] - fReal(y_1, b, j)) * (y_1[j] - fReal(y_1, b, j));
	}
	err = sqrt(err);
	err /= pow(_h, 4);
	printf("%e\n", err);	*/
}
Beispiel #3
0
Datei: 2.cpp Projekt: filaPro/my
void solve() {
    double y_1[N], y_2[N];
    for(int i = 0; i < N; i++) {
        y_1[i] = y_0[i];
        y_2[i] = y_0[i];
    }
    double h = 0.1, b = 1, x = x_0;
    //int i = 0;
    while(x < b) {
        printf("x = %lf, h = %lf | ", x, h);
        for(int j = 0; j < N; j++)
            printf("%lf ", y_1[j]);
        printf("\n");

        newStep(x, y_1, h);
        newStep(x, y_2, h / 2);
        newStep(x + h / 2, y_2, h / 2);

        double err = 0;
        for(int j = 0; j < N; j++)
            err += (y_1[j] - y_2[j]) * (y_1[j] - y_2[j]);
        err /= N;

        if(err > eps) {
            h = h / 2;
            for(int j = 0; j < N; j++)
                y_1[j] = y_2[j];
        } else {
            for(int j = 0; j < N; j++)
                y_2[j] = y_1[j];
        }

        if(x + h > b)
            h = b - x;
        x += h;
    }
}
Beispiel #4
0
GamePainter::GamePainter(QWidget *parent) : QWidget(parent)
{
    m_cellSize = QSize( 30, 30 );
    m_field    = new Field( 15, 15 );
    m_snake    = new Snake( QPoint( 7, 7) );
    m_IsPlay   = false;
    m_gameTimer = new QTimer;
    m_gameSpeed = 160;
    m_score     = 0;

    resize( m_cellSize.width() * ( m_field->getNumWCells() - 2 )
            , m_cellSize.height() * (m_field->getNumHCells() - 2 ) + 30 );


    QPixmap background("../snake_work_version/background.jpg" );
    background.scaled( this->size() );

    QPalette p;
    p.setBrush( this->backgroundRole(), QBrush( background ) );
    this->setPalette(p);

    QIcon windowIcon("../snake_work_version/icon1.png");
    window()->setWindowTitle("Snake");
    window()->setWindowIcon( windowIcon );

    connect( m_snake, SIGNAL(newStep(QPoint,QPoint)), m_field, SLOT(snake_move(QPoint,QPoint)) );
    connect( m_field, SIGNAL(snake_dead()), SLOT(snake_die()) );
    connect( m_field, SIGNAL(snake_ate()), SLOT(snake_eat()));
    connect( m_gameTimer, SIGNAL(timeout()), SLOT(game()) );

    m_settings  = new QSettings( "HOME", "Snake" );
    m_highScore = m_settings->value( HIGH_SCORE_KEY, 0 ).toInt() ;


    QLabel* high_score = new QLabel("<font face=\"mv boli\" color=#40E0D0><strong>High Score: </strong></font>", this );
    high_score->move( 20, -160  );
    high_score->resize( 300, 350 );

    QLabel* score = new QLabel("<font face=\"mv boli\" color=#40E0D0><strong>Score: </strong></font>", this );
    score->move( width() - 100, -160  );
    score->resize( 300, 350 );

    srand(time(0));
}