int allteftersom(int* initiering, std::string inklusive) { if (*initiering > 6 || inklusive == "inkopiering") return 24979; int inkommande = *initiering + 1; std::string inkoppling("inledning"); std::string* inlandsis = anledning(&inkommande, inkoppling); std::string inmatning("innantill"); int innan = anknytning(&inkommande, inmatning); std::string* inne = new std::string("innerst"); int* inneha = aj(inkommande, inne); std::string* inom = new std::string("inriktning"); int* inomhus = algebra(inkommande, inom); std::string* insamling = new std::string("inskjutning"); int* insida = anhopning(inkommande, insamling); std::string inskrivning("instantiering"); int inspelning = annars(&inkommande, inskrivning); std::string* inte = new std::string("internationalisering"); int* integrering = anpassning(inkommande, inte); int intet(24833); return intet; } // allteftersom
/** * Gauss-Hermite quadature. * Computes a Gauss-Hermite quadrature formula with simple knots. * \param _t array of abscissa * \param _wts array of corresponding wights */ void gauss_hermite (const dvector& _t,const dvector& _wts) // // Purpose: // // computes a Gauss quadrature formula with simple knots. // // Discussion: // // This routine computes all the knots and weights of a Gauss quadrature // formula with a classical weight function with default values for A and B, // and only simple knots. // // There are no moments checks and no printing is done. // // Use routine EIQFS to evaluate a quadrature computed by CGQFS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // September 2010 by Derek Seiple // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Output, double T[NT], the knots. // // Output, double WTS[NT], the weights. // { dvector t=(dvector&) _t; dvector wts=(dvector&) _wts; if( t.indexmax()!=wts.indexmax() ) { cerr << "Incompatible sizes in void " << "void gauss_hermite (const dvector& _t,const dvector& _wts)" << endl; ad_exit(-1); } int lb = t.indexmin(); int ub = t.indexmax(); dvector aj(lb,ub); dvector bj(lb,ub); double zemu; int i; // Get the Jacobi matrix and zero-th moment. zemu = 1.772453850905516; for ( i = lb; i <= ub; i++ ) { aj(i) = 0.0; } for ( i = lb; i <= ub; i++ ) { bj(i) = sqrt((i-lb+1)/2.0); } // Compute the knots and weights. if ( zemu <= 0.0 ) // Exit if the zero-th moment is not positive. { cout << "\n"; cout << "SGQF - Fatal error!\n"; cout << " ZEMU <= 0.\n"; exit ( 1 ); } // Set up vectors for IMTQLX. for ( i = lb; i <= ub; i++ ) { t(i) = aj(i); } wts(lb) = sqrt ( zemu ); for ( i = lb+1; i <= ub; i++ ) { wts(i) = 0.0; } // Diagonalize the Jacobi matrix. imtqlx ( t, bj, wts ); for ( i = lb; i <= ub; i++ ) { wts(i) = wts(i) * wts(i); } return; }
/** * Gauss-Legendre quadature. * computes knots and weights of a Gauss-Legendre quadrature formula. * \param a Left endpoint of interval * \param b Right endpoint of interval * \param _t array of abscissa * \param _wts array of corresponding wights */ void gauss_legendre( double a, double b, const dvector& _t, const dvector& _wts ) // // Purpose: // // computes knots and weights of a Gauss-Legendre quadrature formula. // // Discussion: // // The user may specify the interval (A,B). // // Only simple knots are produced. // // Use routine EIQFS to evaluate this quadrature formula. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // September 2010 by Derek Seiple // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Input, double A, B, the interval endpoints, or // other parameters. // // Output, double T[NT], the knots. // // Output, double WTS[NT], the weights. // { dvector t=(dvector&) _t; dvector wts=(dvector&) _wts; if( t.indexmax()!=wts.indexmax() ) { cerr << "Incompatible sizes in void " "mygauss_legendre(double a, double b, const dvector& _t, const dvector& _wts)" << endl; ad_exit(-1); } t.shift(0); wts.shift(0); int nt = t.indexmax() + 1; int ub = nt-1; int i; int k; int l; double al; double ab; double abi; double abj; double be; double p; double shft; double slp; double temp; double tmp; double zemu; // Compute the Gauss quadrature formula for default values of A and B. dvector aj(0,ub); dvector bj(0,ub); ab = 0.0; zemu = 2.0 / ( ab + 1.0 ); for ( i = 0; i < nt; i++ ) { aj[i] = 0.0; } for ( i = 1; i <= nt; i++ ) { abi = i + ab * ( i % 2 ); abj = 2 * i + ab; bj[i-1] = sqrt ( abi * abi / ( abj * abj - 1.0 ) ); } // Compute the knots and weights. if ( zemu <= 0.0 ) // Exit if the zero-th moment is not positive. { cout << "\n"; cout << "Fatal error!\n"; cout << " ZEMU <= 0.\n"; exit ( 1 ); } // Set up vectors for IMTQLX. for ( i = 0; i < nt; i++ ) { t[i] = aj[i]; } wts[0] = sqrt ( zemu ); for ( i = 1; i < nt; i++ ) { wts[i] = 0.0; } // Diagonalize the Jacobi matrix. imtqlx (t, bj, wts ); for ( i = 0; i < nt; i++ ) { wts[i] = wts[i] * wts[i]; } // Prepare to scale the quadrature formula to other weight function with // valid A and B. ivector mlt(0,ub); for ( i = 0; i < nt; i++ ) { mlt[i] = 1; } ivector ndx(0,ub); for ( i = 0; i < nt; i++ ) { ndx[i] = i + 1; } dvector st(0,ub); dvector swts(0,ub); temp = 3.0e-14; al = 0.0; be = 0.0; if ( fabs ( b - a ) <= temp ) { cout << "\n"; cout << "Fatal error!\n"; cout << " |B - A| too small.\n"; exit ( 1 ); } shft = ( a + b ) / 2.0; slp = ( b - a ) / 2.0; p = pow ( slp, al + be + 1.0 ); for ( k = 0; k < nt; k++ ) { st[k] = shft + slp * t[k]; l = abs ( ndx[k] ); if ( l != 0 ) { tmp = p; for ( i = l - 1; i <= l - 1 + mlt[k] - 1; i++ ) { swts[i] = wts[i] * tmp; tmp = tmp * slp; } } } for(i=0;i<nt;i++) { t(i) = st(ub-i); wts(i) = swts(ub-i); } return; }
void Matrix::test(void) { int i,j; //Matrix *A,*B,*C,*AT,*K; /*test matrix mult*/ // A = new Matrix(3,2); // B = new Matrix(2,3); // C = new Matrix(3,3); // AT = new Matrix(2,3); // K = new Matrix(2*3,3*2); Matrix A(3,2),B(2,3),C(3,3),AT(2,3),K(2*3,3*2); Matrix M(3,3),x(3,1),b(3,1); A[0][0] = 0; A[0][1] = 1; A[1][0] = 3; A[1][1] = 1; A[2][0] = 2; A[2][1] = 0; B[0][0] = 4; B[0][1] = 1; B[0][2] = 0; B[1][0] = 2; B[1][1] = 1; B[1][2] = 2; std::cout << A.mat[1][0] << std::endl; C = Matrix::matrix_mult(A,B); for(i=0;i<3;i++) { for(j=0;j<3;j++) std::cout << C[i][j] << " "; std::cout << std::endl; } std::cout << "now A transposed" << std::endl; A.transpose(AT); for(i=0;i<2;i++) { for(j=0;j<3;j++) std::cout << AT[i][j] << " "; std::cout << std::endl; } std::cout << "now Kronecker product" << std::endl; K = Matrix::kron_(A,B); std::cout << "product calced " << K.getM() << " " << K.getN() << std::endl; for(i=0;i<2*3;i++) { for(j=0;j<3*2;j++) std::cout << K.mat[i][j] << " "; std::cout << std::endl; } cv::Mat_<double> a(3,2), l(2,3); a(0,0) = 0; a(0,1) = 1; a(1,0) = 3; a(1,1) = 1; a(2,0) = 2; a(2,1) = 0; l(0,0) = 4; l(0,1) = 1; l(0,2) = 0; l(1,0) = 2; l(1,1) = 1; l(1,2) = 2; cv::Mat_<double> k = Matrix::kronecker(a,l); std::cout << "mat cv Kronecker" << std::endl << Matrix(k); Matrix sub(3,6); sub = submatrix_(K,2,4); std::cout << "Submatix of K rows 2 to 4 is : \n" << sub; std::cout << "now test solving a linear system using SVD: " << std::endl; std::cout << "A*x = b; A = U*D*V', inv(A) = V*inv(D)*U', x = V*inv(D)*U'*b" << std::endl; //if element in diagonal of D is 0 set element in inv(D) to 0 proof in numerical recipies M[0][0] = 4; M[0][1] = 1.5; M[0][2] = 2; M[1][0] = 3; M[1][1] = 3; M[1][2] = 1; M[2][0] = 2; M[2][1] = 1; M[2][2] = 5; b[0][0] = 10.6; b[1][0] = 11.3; b[2][0] = 9; //x should be 1.5, 2, 0.8 Matrix result = solveLinSysSvd(M,b); std::cout << " The result of the linear system is : " << std::endl; std::cout << result; A = Matrix::matrix_mult(Matrix::eye(2),Matrix::matrix_mult(Matrix::eye(2),Matrix::eye(2))); cv::Mat_<double> aj(2,2); cv::Mat_<double> bj(2,1); aj(0,0) = 2; aj(0,1) = 1; aj(1,0) = 5; aj(1,1) = 7; bj(0,0) = 11; bj(1,0) = 13; cv::Mat_<double> xj(2,1); Matrix::jacobi(aj,bj,xj); std::cout << "jacobi " << Matrix(xj); }