void _VerifyGLState(const char* szfile, const char* szfunction, int lineno) { GLenum err = glGetError(); if (err == GL_NO_ERROR) { return; } auto error = glErrors.find(err); if (error != glErrors.end()) { CLog::Log(LOGERROR, "GL(ES) ERROR: {}", error->second); } if (szfile && szfunction) { CLog::Log(LOGERROR, "In file: {} function: {} line: {}", szfile, szfunction, lineno); } GLboolean scissors; glGetBooleanv(GL_SCISSOR_TEST, &scissors); CLog::Log(LOGDEBUG, "Scissor test enabled: {}", scissors == GL_TRUE ? "True" : "False"); GLfloat matrix[16]; glGetFloatv(GL_SCISSOR_BOX, matrix); CLog::Log(LOGDEBUG, "Scissor box: {}, {}, {}, {}", matrix[0], matrix[1], matrix[2], matrix[3]); glGetFloatv(GL_VIEWPORT, matrix); CLog::Log(LOGDEBUG, "Viewport: {}, {}, {}, {}", matrix[0], matrix[1], matrix[2], matrix[3]); PrintMatrix(glMatrixProject.Get(), "Projection Matrix"); PrintMatrix(glMatrixModview.Get(), "Modelview Matrix"); }
int main (int argc, char **argv) { setlocale(0, "Russian"); if (argc < 3) return 0; NumberFromFileParser<double> parser; matrix m1 = parser.parse(argv[1]); matrix m2 = parser.parse(argv[2]); PrintMatrix(m1); PrintMatrix(m2); int max1 = __findMaxElement(m1); int max2 = __findMaxElement(m2); if (max1 < max2) __outputCount(m1); else __outputCount(m2); system("PAUSE"); return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (argc < 3) return __exception("Not found input file"); int mRows1 = 0, mCols1 = 0, mRows2 = 0, mCols2 = 0; double ** matrix1 = __loadMatrix(argv[1], &mRows1, &mCols1); double ** matrix2 = __loadMatrix(argv[2], &mRows2, &mCols2); fprintf(stdout, "Matrix N1:\n"); PrintMatrix(matrix1, mRows1, mCols1); fprintf(stdout, "Matrix N2:\n"); PrintMatrix(matrix2, mRows2, mCols2); int zeroCount1 = GetCount(matrix1, mRows1, mCols1, true); int zeroCount2 = GetCount(matrix2, mRows2, mCols2, true); if (zeroCount1 < zeroCount2) fprintf(stdout, "Output matrix N1: %i\n", GetCount(matrix1, mRows1, mCols1, false)); else fprintf(stdout, "Output matrix N2: %i\n", GetCount(matrix2, mRows2, mCols2, false)); DestroyMatrix(matrix1, mRows1, mCols1); DestroyMatrix(matrix2, mRows2, mCols2); system("pause"); return EXIT_SUCCESS; }
/* test harness */ int main(int argc, char *argv[]) { float m[16], p[16]; float l, r, b, t, n, f; int persp; int i; #if 0 l = -.9; r = 1.2; b = -0.5; t = 1.4; n = 30; f = 84; printf(" Frustum(%f, %f, %f, %f, %f, %f\n",l+1, r+1.2, b+.5, t+.3, n, f); Frustum(l+1, r+1.2, b+.5, t+.3, n, f, p); DecomposeProjection(p, &persp, &l, &r, &b, &t, &n, &f); printf("glFrustum(%f, %f, %f, %f, %f, %f)\n", l, r, b, t, n, f); PrintMatrix(p); #else printf("Ortho(-1, 1, -1, 1, 10, 84)\n"); Ortho(-1, 1, -1, 1, 10, 84, m); PrintMatrix(m); DecomposeProjection(m, &persp, &l, &r, &b, &t, &n, &f); printf("Ortho(%f, %f, %f, %f, %f, %f) %d\n", l, r, b, t, n, f, persp); #endif return 0; }
void test1() { matrix *mx, *u, *v; dvector *w; NewMatrix(&mx, 4, 5); MatrixSet(mx, 0.f); mx->data[0][0] = 1; mx->data[0][4] = 2; mx->data[1][2] = 3; mx->data[3][1] = 4; PrintMatrix(mx); initMatrix(&u); initMatrix(&v); initDVector(&w); svd(mx, &u, &w, &v); puts("U"); PrintMatrix(u); puts("W"); PrintDVector(w); puts("V"); PrintMatrix(v); DelMatrix(&u); DelMatrix(&v); DelDVector(&w); DelMatrix(&mx); }
// ===================================================================================== // Main program. // // ALGORITHM A: Loop until the matrix is not valid, removing a duplicated element at each cycle. This solution is greedy and not optimal. // ===================================================================================== int main(int argc, char *argv[]) { gint l_idx_row = 0; gint l_idx_col = 0; gint l_substitutions = 0; PrintMatrix(); // Algorithm A: NOT the optimal solution while(FALSE == IsAValidHitori(&l_idx_row, &l_idx_col)) { g_assert( l_idx_row >= 0 && l_idx_row < MROW && l_idx_col >= 0 && l_idx_col < MCOL ); w_matrix[l_idx_row][l_idx_col] = NOVAL; l_substitutions++; } g_message("A solution has been found in %d substitutions", l_substitutions); PrintMatrix(); return 0; }
int main() { FullTransform ft; IMatrix i(0); cout << "Generated Hadamard matrix of size " << FullTransform::hms << ':' << endl; PrintMatrix(ft.GetHad()); cout << "Generated negative Hadamard matrix of size " << FullTransform::hms << ':' << endl; PrintMatrix(ft.GetNegHad()); MatrixProduct(ft.GetHad(), ft.GetHad(), i); cout << "Hadamard matrix product on its transpose:" << endl; PrintMatrix(i); CodeWord cw; for(int c = -128; c < 128; ++c) { ft.Code(c, cw); char cc = ft.Decode(cw); if(c == cc) { cout << "Test passed for char: " << (int)c << ", coded word:" << endl; ft.PrintCodeWord(cw); } else { cout << "Test failed for char: " << (int)c << ", decoded char: " << (int)cc << ", coded word:" << endl; ft.PrintCodeWord(cw); break; } } return 0; }
int main() { InitializeMatrix(A); InitializeMatrix(B); MultiplyMatricesParallel(); PrintMatrix(A); PrintMatrix(B); PrintMatrix(C); Verify(); return 0; }
void main(){ //0,0不能为0 TriSeqMatrix M,N,Q; CreateMatrix(&M); PrintMatrix(M); CreateMatrix(&N); PrintMatrix(N); printf("矩阵M和N的乘积为:\n"); MultMatrix(M,N,&Q); PrintMatrix(Q); system("pause"); }
// Find a inverse matrix of a square and check it void InverseSample() { const int iSize = 3; double mTestInit[3][3] = { {1, 2, 0}, { -1, 1, 1}, { 1, 2, 3} }; double **mTest = (double **)malloc(sizeof(double) * iSize); double **mInverse; double **mMulti; int i = 0, j = 0; for(i = 0; i < iSize; i++) { mTest[i] = (double *)malloc(sizeof(double) * iSize); } for(i = 0; i < iSize; i++) { for(j = 0; j < iSize; j++) { mTest[i][j] = mTestInit[i][j]; } } printf("\n======Sample 1 ======\n"); // Print input matrix printf("Test matrix A = \n"); PrintMatrix(mTest, iSize, iSize); // Inverse the matrix mInverse = Inverse(mTest, iSize); printf("Inverse matrix IA = \n"); PrintMatrix(mInverse, iSize, iSize); // Check the inverse matrix multiplied by input matrix is identity matrix mMulti = MultiMatrix(mTest, mInverse, 3, 3, 3); printf("Multiple matrix A * IA = \n"); PrintMatrix(mMulti, iSize, iSize); // Free memory for(i = 0; i < iSize; i++) { free(mTest[i]); free(mInverse[i]); free(mMulti[i]); } free(mTest); free(mInverse); free(mMulti); }
/** \return Array containing which row idx matches which column idx. */ std::vector<int> Hungarian::Optimize() { # ifdef DEBUG_HUNGARIAN mprintf("----- HUNGARIAN ALGORITHM START ------------------------------------------------\n"); PrintMatrix("INITIAL MATRIX"); # endif // Reduce elements in each row by the minimum in each row for (int row = 0; row < nrows_; ++row) { double minval = DBL_MAX; int elt0 = row * ncols_; int elt = elt0; for (int col = 0; col < ncols_; ++col, ++elt) if (matrix_[elt] < minval) minval = matrix_[elt]; for (int col = 0; col < ncols_; ++col, ++elt0) matrix_[elt0] -= minval; } # ifdef DEBUG_HUNGARIAN PrintMatrix("AFTER ROW REDUCTION"); # endif // Reduce elements in each col by the minimum in each col for (int col = 0; col < ncols_; ++col) { double minval = DBL_MAX; int elt0 = col; int elt = elt0; for (int row = 0; row < nrows_; ++row, elt += ncols_) if (matrix_[elt] < minval) minval = matrix_[elt]; for (int row = 0; row < nrows_; ++row, elt0 += ncols_) matrix_[elt0] -= minval; } # ifdef DEBUG_HUNGARIAN PrintMatrix("AFTER COL REDUCTION"); # endif // Loop until every row can be assigned a column int max_iterations = nrows_ * ncols_; int iterations = 0; while (iterations < max_iterations) { // Assign as many columns to rows as possible // If number of assignments == number of rows, done. if ( AssignRowsToColumns() == nrows_ ) break; // Cover zero elts with min # lines possible CoverZeroElements(); // Update matrix according to min elements UpdateMatrix(); ++iterations; } # ifdef DEBUG_HUNGARIAN mprintf("--------------------------------------------------------------------------------\n"); # endif return assignRowToCol_; }
void FlashMyImporter::Import(FlashTagPlaceObject2 &data) { std::cout << "\n<PlaceObject2>\n"; std::cout << "Depth: " << data.GetDepth() << "\n"; if(data.HasCharID()) std::cout << "HasCharID: true [" << data.GetCharID() << "]\n"; else std::cout << "HasCharID: false" << "\n"; if(data.HasMatrix()) { std::cout << "HasMatrix: true" << "\n"; PrintMatrix(data.GetMatrix()); } else std::cout << "HasMatrix: false" << "\n"; if(data.HasColorTransform()) { std::cout << "HasColorTransform: true" << "\n"; PrintCFX(data.GetColorTransform()); } else std::cout << "HasColorTransform: false" << "\n"; if(data.HasMove()) std::cout << "HasMove: true" << "\n"; else std::cout << "HasMove: false" << "\n"; if(data.HasRatio()) std::cout << "HasRatio: true [" << data.GetRatio() << "]\n"; else std::cout << "HasRatio: false" << "\n"; if(data.HasName()) std::cout << "HasName: true [" << data.GetName() << "]\n"; else std::cout << "HasName: false" << "\n"; if(data.HasClipDepth()) std::cout << "HasClipDepth: true [" << data.GetClipDepth() << "]\n"; else std::cout << "HasClipDepth: false" << "\n"; }
int main() { int a[4][4] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; PrintMatrix(a, 4, 4); getchar(); return 0; }
INT WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstanse, CHAR *CmdLine, INT ShowCmd ) { MATRIX M1, M2, M3; VEC V1, V2; static char BUF[300]; /* M1 = MatrIdenity( ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, "I matric ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrTranslate( 1, 3, 25 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, "Transpose matric (x = 1, y = 3, z = 25) ( M1 )", MB_OK | MB_ICONINFORMATION ); M2 = MatrScale(2, 4, 8); PrintMatrix( BUF, M2 ); MessageBox( NULL, BUF, "Scale matric (x = 2, y = 4, z = 8) ( M2 )", MB_OK | MB_ICONINFORMATION ); M3 = MatrMulMatr( M1, M2 ); PrintMatrix( BUF, M3 ); MessageBox( NULL, BUF, " M1 * M2 ( M3 )", MB_OK | MB_ICONINFORMATION ); M3 = MatrMulMatr( M2, M1 ); PrintMatrix( BUF, M3 ); MessageBox( NULL, BUF, " M2 * M1 ( M3 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrTranspose( M3 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " (M3)t ( M1 )", MB_OK | MB_ICONINFORMATION ); M2 = MatrInverse( M3 ); PrintMatrix( BUF, M2 ); MessageBox( NULL, BUF, " (M3)^-1 ( M2 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrMulMatr( M3, M2 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " M3 * M2 ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrMulMatr( M2, M3 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " M2 * M3 ( M1 )", MB_OK | MB_ICONINFORMATION );*/ /* M1 = MatrRotateX( 30 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateY( 30 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate Y 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateZ( 30 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate Z 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );*/ /* M1 = MatrRotateX( 30 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateVec( 30, 1, 0, 0 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateVec( 30, -1, 0, 0 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateVec( 30, 0, 1, 0 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateVec( 30, 0, 0, 1 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION ); M1 = MatrRotateVec( 30, 1, 1, 1 ); PrintMatrix( BUF, M1 ); MessageBox( NULL, BUF, " rotate (1,1,1) 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );*/ PrintMatrix( "Ematr", MatrIdenity( ) ); }
void main() { int **matrix; int col, row, i, j, ch; do { system("cls"); printf("Enter the size of a matrix:\n\tcol = "); scanf("%d", &col); printf("\trow = "); scanf("%d", &row); if (col > 0 && row > 0) { matrix = (int**) calloc(row, sizeof(int*)); for (i = 0; i < row; i++) matrix[i] = (int*) calloc(col, sizeof(int)); SetData(matrix, row, col); putchar('\n'); PrintMatrix(matrix, row, col); for (i = 0; i < col; i++) BubbleSort(matrix,row, i); Proverka(matrix, row, col); for (i = 1; i < row; i++) free(matrix[i]); free(matrix); } else printf("ERROR: Wrong input!!!"); printf("\n\nRepeat? (y/n)"); } while (tolower((ch = getch())) == 'y'); }
///Part 3 of the project void part3( ) { //array containing the filenames of different files used in the project. //this makes is easy to quickly switch files char* filenames[] = { "Binary02.mtx", "Binary03.mtx", "Binary04.mtx" }; char* filename = filenames[ 0 ]; //**Set the filename here from the array of filenames** matrix A, EigenVec, EigenVal,EigDecomposition; int Rows, Columns; double EigCondition, MatCondition; //reads the BinaryMatrix for the particular file chosen from the 'filename' array A = ReadBinaryMatrix( filename ); Rows = A.wide( ); Columns = A.high( ); EigenVal = eye( Rows ); EigenVec = matrix( Rows, Columns ); EigenVec = EigenV_V( A, EigenVal ); EigCondition = EigenVal( 0, 0 ) / EigenVal( Rows - 1, Rows - 1 ); MatCondition = A.condition( ); EigDecomposition = EigenVec*EigenVal*EigenVec.transpose( ); printf( "Input Matrix '%s'\n", filename ); PrintMatrix( A ); //prints the input matrix //This prints the condition of the matrix. It is calculated //in two different ways. The first uses the built in Condition() from //the Matrix.hpp file. The second uses out custom condition function. printf( "condition from object = %lf\n", MatCondition ); printf( "condition from eigens = %lf\n\n", EigCondition ); printf( "EigenValues Matrix\n" ); PrintMatrix( EigenVal ); printf( "\n" ); printf( "EigenVector Matrix\n" ); PrintMatrix( EigenVec ); printf( "\n" ); printf( "Test of Eigen Decomposition (V*D*V') = A\n" ); PrintMatrix( EigDecomposition ); printf( "\n" ); }
CvMat *Morphining::GetAffineMatrix(vector<Coordinate> coord1,vector<Coordinate>coord2,bool debug) { //b_temp:affine transformation,b_temp_inv:inverse of affine transform CvMat *b_temp = cvCreateMat(3, 3, CV_32FC1); CvMat *b_temp_inv = cvCreateMat(3, 3, CV_32FC1); CvMat *B = cvCreateMat(3, 3, CV_32FC1); CvMat *X = cvCreateMat(3, 3, CV_32FC1); CvMat *X_Inv = cvCreateMat(3, 3, CV_32FC1); // x1' = w11 * x1 + w12 * y1 + w13 // y1' = w21 * x1 + w22 * y1 + w13 // x2' = w11 * x2 + w12 * y2 + w13 // y2' = w21 * x2 + w22 * y2 + w13 // x3' = w11 * x3 + w12 * y3 + w13 // y3' = w21 * x3 + w22 * y3 + w13 // Ax = b x:left or right b:front face for(int i = 0;i < 3;i++) { cvSetReal2D(B, 0, i, coord1[i].x); cvSetReal2D(B, 1, i, coord1[i].y); cvSetReal2D(B, 2, i, 1); } for(int i = 0;i < 3;i++) { cvSetReal2D(X, 0 , i, coord2[i].x); cvSetReal2D(X, 1 , i, coord2[i].y); cvSetReal2D(X, 2 , i, 1); } cvInv(X, X_Inv); cvmMul(B,X_Inv,b_temp); cvInv(b_temp,b_temp_inv); if(debug) { cout << "b_temp:\n"; PrintMatrix(b_temp,3,3); cout << "b_temp_inv:\n"; PrintMatrix(b_temp_inv,3,3); } cvReleaseMat(&B); cvReleaseMat(&X); cvReleaseMat(&X_Inv); cvReleaseMat(&b_temp); //return b_temp; return b_temp_inv; }
main (int argc, char* argv[]) { if (argc<3 or argc>4 ) { std::cout << std::endl; std::cout << " " << MatrixExp_VERSION_MAJOR << "." << MatrixExp_VERSION_MINOR << std::endl; std::cout << " The tricky matrix exponential. An elementary check \n \n"; std::cout << " usage: " << argv[0] << " {matrix size} {order of the expansion} {optional: if set to whatever number/string, will set the matrix to identity (for testing)}\n"; return 0; } int n,N; n=atoi(argv[1]); N=atoi(argv[2]); std::cout << std::endl; std::cout << " " << MatrixExp_VERSION_MAJOR << "." << MatrixExp_VERSION_MINOR << std::endl; std::cout << " The tricky matrix exponential. An elementary check \n \n"; std::cout << tag << std::endl; std::cout << " Matrix size ---> " << n << std::endl; std::cout << " order of the Taylor expasion of exp(A) ---> "<< N << std::endl << std::endl; double* A; A=new double[n*n]; double temp; #if c11 > 0 //c++11-style random number generation for gaussian random numbers FillMatrix_c11(A,n); #else //using Box-Muller transform FillMatrix(A,n); #endif if (argc==4) { std::cout << " Testing using identity matrix " << std::endl; for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i==j) A[i*n+j]=1.0; else A[i*n+j]=0.0; } } } // printing input matrix PrintMatrix(A,n); //Calculating Tr(exp(A)) using our dgemm fortran wrapper double ans1; ans1 = traceexp_(A,&n,&N); std::cout << std::fixed << std::setprecision(14); std::cout << " Tr(exp(A)) = " << ans1 << std::endl << std::endl; //Calculating exp(\sum_i \lambda_i) using our dsyev fortran wrapper double ans2; ans2 = expeigenval_(A,&n); std::cout << " Sum_i exp( lambda_i ) = " << ans2 << std::endl << std::endl; std::cout << " Difference between the two methods " << ans1-ans2 << std::endl << std::endl; delete [] A; return 0; }
int main() { CreateMatrix(); printf("The number of vertices is %d\n\n",NrOfVertices); printf("The adjacency matrix is:\n"); PrintMatrix(); int choice; printf("\nChoose which algorithm you want to apply:\n"); printf(" press 1 for Dijkstra \n 2 for Floyd-Warshall\n"); scanf("%d",&choice); switch(choice) { case 1: printf("\nDijkstra\n"); int FirstPosition,LastPosition; //I've tried to do what's in the comment,but it didn't work. I couldn't read LastVertex //I saw on the internet that are some problems with scanf and char.. and I used gets. But still no success /* int i; char FirstVertex,LastVertex; printf("\nInput the vertex from which you want to start Dijkstra's algorithm\n"); //scanf("%d ",&FirstVertex); gets(FirstVertex); printf("Input the vertex where you want to stop Dijkstra's algorithm\n"); //scanf("%d ",&LastVertex); gets(LastVertex); for(i=0; i<NrOfVertices; i++) { if(FirstVertex==vertices[i]) FirstPosition=i; if(LastVertex==vertices[i]) LastPosition=i; } */ printf("\nInput the number of the vertex from where you want to start\n"); scanf("%d",&FirstPosition); printf("\nInput the number of vertex where you want to stop\n"); scanf("%d",&LastPosition); Dijkstra(FirstPosition,LastPosition); break; case 2: printf("\nThe matrix of Floyd-Warshall algorithm is\n"); FloydWarshall(); break; default: printf("\nInvalid number\n"); } return 0; }
int main(int argc, char **argv) { if (argc < 3) return __exception("Not found input file"); int mRows1 = 0, mCols1 = 0, mRows2 = 0, mCols2 = 0; double ** matrix1 = __loadMatrix(argv[1], &mRows1, &mCols1); double ** matrix2 = __loadMatrix(argv[2], &mRows2, &mCols2); fprintf(stdout, "Matrix N1:\n"); PrintMatrix(matrix1, mRows1, mCols1); fprintf(stdout, "Matrix N2:\n"); PrintMatrix(matrix2, mRows2, mCols2); int S1 = Calculate(matrix1, mRows1, mCols1); int S2 = Calculate(matrix2, mRows2, mCols2); int row, cols; double ** matrix; if(S1 < S2) { matrix = matrix1; row = mRows1; cols = mCols1; } else { matrix = matrix2; row = mRows2; cols = mCols2; } for (int i = 0; i < row; i++) printf("Min element %i line = %3.1f\n", i+1, CalculateRow(matrix, i, cols)); DestroyMatrix(matrix1, mRows1, mCols1); DestroyMatrix(matrix2, mRows2, mCols2); system("pause"); return EXIT_SUCCESS; }
int main() { AdjMatrix *a; a=(AdjMatrix *)malloc(sizeof(AdjMatrix)); Created(a); printf("\n\n"); PrintMatrix(a); }
int main(){ printf("\nMatrix With Alternating O and X's rectangle\n"); //PrintMatrix(3,3); //PrintMatrix(4,5); //PrintMatrix(5,5); PrintMatrix(6,7); return 0; }
void PrintLDAModel(LDAMODEL* m) { puts("Eigenvalues"); PrintDVector(m->eval); puts("Eigenvectors"); PrintMatrix(m->evect); puts("Features"); PrintArray(m->features); puts("Multivariate Normal Distribution"); PrintArray(m->mnpdf); puts("Class Average. Each row represent a class"); PrintMatrix(m->mu); puts("Validation..."); puts("Senstivity"); PrintDVector(m->sens); puts("Specificity"); PrintDVector(m->spec); puts("Positive Predicted Value"); PrintDVector(m->ppv); puts("Negative Predicted Value"); PrintDVector(m->npv); puts("Accuracy"); PrintDVector(m->acc); }
void FlashMyImporter::Import(FlashTagPlaceObject &data) { std::cout << "\n<PlaceObject>\n"; std::cout << "Character ID: " << data.GetCharID() << "\n"; std::cout << "Depth: " << data.GetDepth() << "\n"; std::cout << "Matrix: " << "\n"; PrintMatrix(data.GetMatrix()); if(data.HasColorTransform()) std::cout << "HasColorTransform: true" << "\n"; else std::cout << "HasColorTransform: false" << "\n"; }
// Find a transpose matrix of a none square matrix void TransposeSample() { const int iSizeM = 2, iSizeN = 3; double mTestInit[2][3] = { {1, 2, 0}, { -1, 1, 1} }; double **mTest = (double **)malloc(sizeof(double) * iSizeM); // Important index is M double **mTranspose; int i = 0, j = 0; for(i = 0; i < iSizeM; i++) { // Important index is M mTest[i] = (double *)malloc(sizeof(double) * iSizeN); // Important index is N } for(i = 0; i < iSizeM; i++) { for(j = 0; j < iSizeN; j++) { mTest[i][j] = mTestInit[i][j]; } } printf("\n======Sample 2 ======\n"); // Print input matrix printf("Test matrix A = \n"); PrintMatrix(mTest, iSizeM, iSizeN); // Transpose the matrix mTranspose = Transpose(mTest, iSizeM, iSizeN); printf("Transpose matrix TA = \n"); PrintMatrix(mTranspose, iSizeN, iSizeM); for(i = 0; i < iSizeM; i++) { free(mTest[i]); } for(i = 0; i < iSizeN; i++) { free(mTranspose[i]); } free(mTest); free(mTranspose); }
Matrix OrthoProjection(double left, double right, double bottom, double top, double nearPlane, double farPlane){ double FplusN = farPlane + nearPlane; double FminN = farPlane - nearPlane; Matrix P; P.e[0] = (float) 2/(right-left); P.e[4] = 0.00000f; P.e[8] = 0.00f; P.e[12] = (float) -((right + left)/(right - left)); P.e[1] = 0.0000f; P.e[5] = (float) 2/(top-bottom); P.e[9] = 0.000f; P.e[13] =(float) -((top+bottom)/(top-bottom)); P.e[2] = 0.0000f; P.e[6] = 0.0000f; P.e[10] = (float) 2 / (nearPlane - farPlane); P.e[14] = (float) -(FplusN/FminN); P.e[3] = 0.0000f; P.e[7] = 0.0000f; P.e[11] = 0.0000f; P.e[15] = 1.00f; PrintMatrix("Matrix P: ", P); return P; }
main() { float **matrix; int i, j; int seed; int n; printf("Enter seed for RNG: "); scanf("%d", &seed); srand48(seed); /* seed the number generator */ printf("Enter n (for an n x n matrix): "); scanf("%d", &n); matrix = AllocateMatrix(n,n); PrintMatrix(matrix,n,n); printf("\n\n"); for(i=0; i<n; i++) for(j=0; j<n; j++) matrix[i][j] = (float)drand48(); PrintMatrix(matrix,n,n); }
int main() { int row, column; ElemType **matrixa, **matrixb, **matrixadd, **matrixtran; //矩阵 TSMatrix arraya, arrayb, arrayadd, arraytran; //三元组 while (scanf("%d%d", &row, &column) != EOF && row*column) { CreateMatrix(&matrixa, row, column); //随机生成矩阵A printf("正在生成稀疏矩阵......\nDone!\nA矩阵:\n"); PrintMatrix(matrixa, row, column); //输出矩阵 printf("A矩阵的三元组:\n"); //输出A的三元组 MatrixToArray(matrixa, &arraya, row, column); //矩阵A转换为三元组 freeMatrix(&matrixa, row); PrintArray(arraya); printf("A矩阵的转置矩阵(快速转置得到):\n"); transpose(arraya, &arraytran); ArrayToMatrix(arraytran, &matrixtran); freeArray(&arraytran); PrintMatrix(matrixtran, column, row); freeMatrix(&matrixtran, column); CreateMatrix(&matrixb, row, column); //随机生成矩阵B printf("正在生成稀疏矩阵......\nDone!\nB矩阵:\n"); PrintMatrix(matrixb, row, column); printf("B矩阵的三元组:\n"); MatrixToArray(matrixb, &arrayb, row, column); freeMatrix(&matrixb, row); PrintArray(arrayb); printf("C矩阵(C=A+B):\n"); AddMatrixArray(arraya, arrayb, &arrayadd); freeArray(&arraya); freeArray(&arrayb); ArrayToMatrix(arrayadd, &matrixadd); freeArray(&arrayadd); PrintMatrix(matrixadd, row, column); freeMatrix(&matrixadd, row); } return 0; }
task main() { // Initiate BNS Library BNS(); // Create a 3x3 matrix of zeros Matrix mat1; CreateZerosMatrix(&mat1, 3, 3); // Create a 3x3 matrix with some data in it // Set location 1 down, 0 across, to be 16 Matrix mat2; CreateMatrix(&mat2, "1.10 3.40 0; 5 3 2; 0 1 1.234"); SetMatrixAt(&mat2, 1, 0, 16); // Creates a 3x3 identity matrix, then multiply it by 11 Matrix mat3; CreateIdentityMatrix(&mat3, 3); MatrixMultiplyScalar(&mat3, 11); // Print matricies to the debugger console PrintMatrix(&mat1); PrintMatrix(&mat2); PrintMatrix(&mat3); // Matrix Examples: // Matrix determinant float det = MatrixDeterminant(&mat2); writeDebugStreamLine("Matrix Det = %f", det); // Matrix Inverse Matrix inv; MatrixInv(&inv, mat2); writeDebugStream("Inverse "); PrintMatrix(&inv); // Matrix Multiplication Matrix mult; MatrixMult(&mult, mat2, mat3); writeDebugStream("Multiply "); PrintMatrix(mult); // Matrix Addition Matrix add; MatrixAdd(&add, mat2, mat3); writeDebugStream("Add "); PrintMatrix(&add); // Matrix Subtraction Matrix sub; MatrixSub(&sub, mat3, mat2); writeDebugStream("Subtract "); PrintMatrix(&sub); }
//****************************************************************** //FUNCTION: void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glPushMatrix(); // glMatrixMode(GL_MODELVIEW); // gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // glTranslatef(0.1, 0.2, 0.3); // glRotatef(30.0, 1, 2, 3); // glScalef(0.5, 0.5, 0.5); // // glMatrixMode(GL_PROJECTION); // gluPerspective(60, 1, 1, 10); // glOrtho(-3, 5, -3, 5, -1, 10); // // float ModelView[16]; // glGetFloatv(GL_MODELVIEW_MATRIX, ModelView); // PrintMatrix(ModelView); // // glm::mat4 Projection; // glGetFloatv(GL_PROJECTION_MATRIX, &Projection[0][0]); // PrintMatrix(&Projection[0][0]); // glPopMatrix(); CPileline* pPileline = new CPileline; pPileline->lookAt(glm::vec3(0.0, 0.0, 5), glm::vec3(0.0, 0.0, 0), glm::vec3(0.0, 1.0, 0.0)); pPileline->translate(0.0, 0.0, 3.0); pPileline->rotate(Scale, 0.0, 1.0, 0); pPileline->scale(0.5, 0.5, 0.5); pPileline->perspective(60, 1, 1.0, 100); //pPileline->ortho(-3, 5, -3, 5, -1, 10); glm::mat4 Model = pPileline->getModelMat(); glm::mat4 View = pPileline->getViewMat(); glm::mat4 Project = pPileline->getProjectMat(); glm::mat4 ProjectModelView = Project * View * Model; PrintMatrix(&ProjectModelView[0][0]); g_Shader->useShader(); g_Shader->setMatUniformValue("uWorld", &ProjectModelView[0][0]); g_VBO->useVBO(0); g_ColorVBO->useVBO(1); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_IBO); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0); //glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); //glDisableVertexAttribArray(1); g_Shader->banShader(); glutSwapBuffers(); }