// création des états adjoints Z
void Calculs::construction_adjoints()
{
       transposition(dGdU);
       transposition(dGdX);
       transposition(dFdU);
       transposition(dFdX);
       Z.resize(35);
       for(i=0;i<Z.size();i++)                               // initialisation de Z
       {                                                     //
               Z[i].resize(34);                              //
       }                                                     //
       for(i=0;i<Z.size();i++)                               //
       {                                                     //
               for(j=0;j<Z[i].size();j++)                    //
               {                                             //
                       Z[i][j] = 0;                          //
               }                                             //
       }                                                     //
       for(i=0;i<Id.size();i++)
       {
               for(j=0;j<Id[i].size();j++)
               {
                        dFdX[i][j] = dFdX[i][j] + Id[i][j];
               }
       } 
       for(i=33;i>-1;i--)
       {
               for(j=0;j<dFdX[0].size();j++)
               {
                        AA = produit(dFdX,Z[i+1]);
                        Z[i][j] = AA[j]-dGdX[j][i];
               }
       }
       //for(j=0;j<35;j++){
//       for(i=0;i<34;i++)
//       {
//                        cout << Z[j][i] << " " ;
//       }
//       cout << endl;}              
}
Пример #2
0
void PolyaevaEV::lab8()
{
	double norm, eps = 0.0001;
	double** M = new double*[N];
	double** MT = new double*[N];
	double** AA = new double*[N];
	zeroing(x);

	for (int i = 0; i < N; i++)
	{
		AA[i] = new double[N];
		for (int j = 0; j < N; j++) AA[i][j] = 0;
	};

    do
	{
		int i_max = 0, j_max = 1;
		double max_el = abs(A[0][1]);

		for (int i = 0; i < N; i++)
			for (int j = i+1; j < N; j++)
				if (abs(A[i][j]) >= max_el) { max_el = abs(A[i][j]); i_max = i; j_max = j; };
		double phi = atan(2*max_el/(A[i_max][i_max] - A[j_max][j_max]))/2;

		for (int i = 0; i < N; i++) {
			M[i] = new double[N]; MT[i] = new double[N];
			for (int j = 0; j < N; j++) { MT[i][j] = 0; if(i == j) M[i][j] = 1; else M[i][j] = 0; };
		};
		M[i_max][i_max] = M[j_max][j_max] = cos(phi);
		M[i_max][j_max] = - sin(phi);
		M[j_max][i_max] = sin(phi);

		transposition(M, MT);
		multiplication(MT, A, AA);
		multiplication(AA, M, A);

    norm = 0;
    for (int i = 0; i < N; i++)
			  for (int j = i+1; j < N; j++) norm += pow(A[i][j],2);
    } while (sqrt(norm) > eps);
	for(int i = 0; i < N; i++) x[i] = A[i][i];

	delete[] M;
	delete[] MT;
	delete[] AA;
}
int main()
{
	int a[4][4],i,j;
	printf("请任意输入一个3*3的二维整型数组:\n");
	for(i=1;i<4;i++)
	{
		for(j=1;j<4;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	transposition(a);
	printf("该数组的转置数组为:\n");
	for(i=1;i<4;i++)
	{
		for(j=1;j<4;j++)
		{
		    printf("%d ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}
Пример #4
0
void rnmatrix<T>::transposition()
{
	*this = transposition(*this);
}
Пример #5
0
struct map_type *dfp( function func,
                      struct map_type *map_x,
                      __float128 grad_toler,
                      __float128 fx_toler,
                      const unsigned int max_iter )
{
    unsigned int iter;
    __float128 lambda, result_func_value, temp_func_value;
    struct map_type *result, *b, *grad1, *tmp, *s, *grad2,
            *g, *tmp2, *tmp3, *d, *x1, *x2, *x3, *x4, *x5;

    result = NULL;
    result_func_value = func( map_x );

    b = get_identity_matrix( map_x->j_size );
    grad1 = first_derivatives( func, map_x );
    tmp = transposition( grad1 );
    deallocate( grad1 );
    grad1 = tmp;
    for( iter = 0 ; iter < max_iter; iter++ )
	{
        tmp = multiplicate_on_value( -1, b );
        s = multiplicate( tmp, grad1 );
        deallocate( tmp );

        tmp = transposition( s );
        tmp2 = multiplicate_on_value( powf( get_euclidean_distance( s ), -1 ), tmp );
        deallocate( s );
        deallocate( tmp );
        s = tmp2;

        lambda = 1;
        lambda = line_search( func, map_x, lambda, s );
        d = multiplicate_on_value( lambda, s );

        tmp = addition( map_x, d );
        deallocate( d );
        deallocate( map_x );
        map_x = tmp;
        temp_func_value = func( map_x );
        if( result_func_value > temp_func_value )
        {
            iter = 0;
            result_func_value = temp_func_value;
            if( result != NULL )
            {
                deallocate( result );
            }
            result = clone( map_x );
        }

        grad2 = first_derivatives( func, map_x );
        tmp = transposition( grad2 );
        deallocate( grad2 );
        grad2 = tmp;
        g = subtraction( grad2, grad1 );
        deallocate( grad1 );
        grad1 = grad2;
        if( get_euclidean_distance( grad1 ) < grad_toler )
        {
            /// TODO: Нужно очистить память
            break;
        }

        tmp = transposition( s );
        x1 = multiplicate( s, tmp );
        x2 = multiplicate( s, g );
        deallocate( s );
        deallocate( tmp );

        tmp = multiplicate_on_value( lambda, x1 );
        tmp2 = get_inverse( x2 );
        tmp3 = multiplicate( tmp, tmp2 );
        deallocate( tmp );
        tmp = addition( b, tmp3 );
        deallocate( x1 );
        deallocate( x2 );
        deallocate( tmp2 );
        deallocate( tmp3 );
        deallocate( b );
        b = tmp;

        x3 = multiplicate( b, g );
        tmp = transposition( b );
        x4 = multiplicate( tmp, g );
        deallocate( tmp );

        tmp = transposition( g );
        tmp2 = multiplicate( tmp, b );
        x5 = multiplicate( tmp2, g );
        deallocate( g );
        deallocate( tmp );
        deallocate( tmp2 );

        tmp = transposition( x4 );
        tmp2 = multiplicate( x3, tmp );
        deallocate( tmp );
        tmp = get_inverse( x5 );
        tmp3 = multiplicate( tmp, tmp2 );
        deallocate( tmp );

        tmp = subtraction( b, tmp3 );
        deallocate( b );
        b = tmp;

        deallocate( tmp2 );
        deallocate( tmp3 );
        deallocate( x3 );
        deallocate( x4 );
        deallocate( x5 );
    }
    return result;
}