Example #1
0
    FieldType<rank, dim> line_search(
      const Functional& F,
      const FieldType<rank, dim>& phi,
      const FieldType<rank, dim, dual>& df,
      const FieldType<rank, dim, primal>& p,
      const double eps
    )
    {
      // Compute the angle between the search direction and the gradient of the
      // objective functional; we need this
      const double theta = inner_product(df, p);

      // Make a lambda function giving the value of the objective along the
      // search direction.
      const auto f = [&](const double alpha) { return F(phi + alpha * p); };

      // Find an endpoint to bound the line search.
      // TODO: make the parameters 1.0e-4, 0.5 adjustable, but default to the
      // values given in Nocedal & Wright.
      const double end_point = armijo(f, theta, 1.0e-4, 0.5);

      // Locate the minimum of the objective functional along the search,
      // within the bounds obtained using the Armijo rule.
      const double alpha = golden_section_search(f, 0.0, end_point, eps);

      return phi + alpha * p;
    }
Example #2
0
int rechne() {
	//double temp = 0.0;

	double *richtung;
	double schritt = 0.0;
	double x = start_x;
	double y = start_y;
	double z = start_z;
	double x_neu = 0.0;
	double y_neu = 0.0;
	double z_neu = 0.0;
	int i = 0;
	//test();	//test-Daten	

	//double funkt = 0.0;
	//funkt = f(x,y,z,n);
	//printf("funktion: %lf\n",funkt);	

	

	while(i<2000)
	{
	  //printf("iter:%d\n",i);
		richtung = grad_f(x,y,z,n);
		//printf("richtung: %lf  ", richtung[0]);
		//richtung[0] = -richtung[0];
		//printf("richtung-neg: %lf  ", richtung[0]);
		//richtung[1] = -richtung[1];
		//richtung[2] = -richtung[2];
		schritt = armijo(x,y,z,n);

		x_neu = x - schritt*richtung[0];
		y_neu = y - schritt*richtung[1];
		z_neu = z - schritt*richtung[2];
		i++;
		//auf Staionaritaet pruefen
		if (((x-x_neu)*(x-x_neu)+(y-y_neu)*(y-y_neu)+(z-z_neu)*(z-z_neu))<0.0001)
			break;
		x = x_neu;
		y = y_neu;
		z = z_neu;
		//funkt = f(x,y,z,n);
		//printf("schritt: %lf  ",schritt);
		//temp = schritt*richtung[0];
		//printf("multi: %lf\n", temp);

	}

	x = x_neu;
	y = y_neu;
	z = z_neu;
    
    posx = x;
    posy = y;
    posz = z;

	//printf("Iterationen: %i  Position: x = %lf, y = %lf, z = %lf\n",i,x,y,z);
    int ret = 0;
	return ret;
}
//Start Berechnung der Koordinaten
void ips::rechne()
{
    double richtung[3]={0};
    double schritt = 0.0;
    double x = start_x;
    double y = start_y;
    double z = start_z;
    double x_neu = 0.0;
    double y_neu = 0.0;
    double z_neu = 0.0;
    int i = 0;


    while(i<300)
    {
        //Grad (google it!!)
        gradf(x,y,z);
        richtung[0] = erg[0];
        richtung[1] = erg[1];
        richtung[2] = erg[2];
        //Schrittweite nach Armijo (google it!!)
        schritt = armijo(x,y,z);
        //qDebug() << schritt;
        x_neu = x - schritt*richtung[0];
        //qDebug() << x_neu;
        y_neu = y - schritt*richtung[1];
        z_neu = z - schritt*richtung[2];
        i++;

        //auf Staionaritaet pruefen
        if (((x-x_neu)*(x-x_neu)+(y-y_neu)*(y-y_neu)+(z-z_neu)*(z-z_neu))<0.0001)
        { break;}
        x = x_neu;
        y = y_neu;
        z = z_neu;

    }
    qDebug() << "Anzahl der Schleifen:" << i;

    if(i==300)
    {
        posx=0;
        posy=0;
        posz=0;
        qDebug()<< "Keine Annäherung in 300 Schritten möglich";
    }
    else
    {
        posx = x_neu;
        posy = y_neu;
        posz = z_neu;
    }
}