本文整理汇总了C++中printMatrix函数的典型用法代码示例。如果您正苦于以下问题:C++ printMatrix函数的具体用法?C++ printMatrix怎么用?C++ printMatrix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printMatrix函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
matrix m, n, r, t;
m = initmatrix(4,5);
printf("matrix m:\n");
printMatrix(&m);
n = initmatrix(4,4);
unitMatrix(&n);
printf("matrix n:\n");
printMatrix(&n);
r = initmatrix(6,6);
unitMatrix(&r);
printf("matrix r:\n");
printMatrix(&r);
t = initmatrix(6,6);
// t = initMatrix(6,6);
printf("enter row num: ");
int rown, coln, val;
scanf("%d", &rown);
printf("\nenter col num: ");
scanf("%d", &coln);
printf("\nenter value: ");
scanf("%d", &val);
if (rown >= 6 || coln >= 6)
{
printf("row or col number out of bounds!\n");
return 1;
}
t.data[rown][coln] = val;
//t.data[2][2] = 1;
printf("matrix t:\n");
printMatrix(&t);
}
开发者ID:itp2-bge,项目名称:Matrix-C,代码行数:44,代码来源:TestMatrix.c
示例2: nullifyMatrix
static void
nullifyMatrix()
{
int i, j;
bool firstRow = false;
bool firstCol = false;
// first row
for (i = 0; i < M; i++)
if (a[0][i] == 0) {
firstRow = true;
break;
}
// first col
for (i = 0; i < N; i++)
if (a[i][0] == 0) {
firstCol = true;
break;
}
// rest of the matrix
for (i = 1; i < N; i++)
for (j = 1; j< M; j++)
if (a[i][j] == 0) {
a[i][0] = 0;
a[0][j] = 0;
}
printf("D1:\n");
printMatrix();
// now we know which row and column to be nullify using information stored in previous step.
// row first
for (i = 1; i < N; i++)
if (a[i][0] == 0)
nullifyRow(i);
// cols now
for (j = 1; j < M; j++)
if (a[0][j] == 0)
nullifyCol(j);
printf("D2:\n");
printMatrix();
// now first row:
if (firstRow) nullifyRow(0);
// now rist col:
if (firstCol) nullifyCol(0);
}
开发者ID:iRoy7,项目名称:algo-progs,代码行数:44,代码来源:cr_zero_matrix.cpp
示例3: matrixFill
void matrixFill(int lines, int col, int mat[lines][col]){
int i, j;
for(i = 0; i < lines; i++){
for(j = 0; j < col; j++){
printf("Digite o termo [%d][%d]: ", i + 1, j + 1);
scanf("%d", &mat[i][j]);
}
}
printMatrix(lines, col, mat);
}
开发者ID:thiago6196,项目名称:ED,代码行数:10,代码来源:McAngus.Lista2.c
示例4: main
int main () {
int i = 0;
int j = 0;
int k = 0;
int l = 0;
for(k=0; k<3; k++) {
for(l=0; l<3; l++) {
U[k][l] = 0;
if(k==l) {
U[k][l] = 1;
}
L[k][k] = M[k][k] - summation(k,-1, 0);
for(i=k+1;i<3;i++) {
L[i][k] = M[i][k] - summation(k, i, 1);
}
for(j=k+1;j<3;j++) {
U[k][j] = (M[k][j] - summation(k, j, 2)) / L[k][k];
}
}
}
printMatrix(U, 'M');
printMatrix(U, 'U');
printMatrix(L, 'L');
y_1 = B[0] / L[0][0];
y_2 = (B[1] - L[1][0] * y_1) / L[1][1];
y_3 = (B[2] - (L[2][0] * y_1) - (L[2][1] * y_2)) / L[2][2];
printf("y_1, y_2, y_3: %0.2f, %0.2f, %0.2f\n", y_1, y_2, y_3);
x_3 = y_3;
x_2 = y_2 - U[1][2] * x_3;
x_1 = y_1 - U[0][1] * x_2 - U[0][2] * x_3;
printf("x_1, x_2, x_3: %0.2f, %0.2f, %0.2f", x_1, x_2, x_3);
return 0;
}
开发者ID:CitlaliRem,项目名称:UNAM-Programacion_Avanzada,代码行数:43,代码来源:pract6-2.c
示例5: printConsole
void Field::printAll() {
if (t > nextFrameTime) {
nextFrameTime += algo::ftr().TMax() / algo::ftr().FramesCount();
printConsole();
printViews();
printMatrix();
printTimes();
}
}
开发者ID:bamx23,项目名称:diploma,代码行数:10,代码来源:field-print.cpp
示例6: problem42_1
/*
* Problems...
* ------
* Computer problem 4.2 #1
*/
void problem42_1()
{
// variables
struct matrix a,ai,aai,im;
struct lu lu;
// setup
a.size = NUM10;
ai.size = NUM10;
aai.size = NUM10;
im.size = NUM10;
// print
printf("Problem 4.2 #1\n");
printf("Algorithm for inverting an nxn lower triangular matrix A.\n");
printf("Testing on matrix whose elements are aij = (i+j)^2 when i >= j.\n");
printf("Use n = 10. Form AA^-1 as test.\n");
// do the work
a.m10 = loadMatrix42_1();
im = loadIdentityMatrix(NUM10);
lu = luDecomposition(a);
ai.m10 = evaluateLu(lu.lu10,im.m10);
aai = multiplyMatrix(a,ai);
// Original matrix
printf("\nOriginal Matrix: A\n");
printMatrix(a);
// Identity matrix
printf("\nIdentity Matrix: I\n");
printMatrix(im);
// LU decomposition
printf("\nLU decomposition:\n");
printLu10(lu.lu10);
// Inverted matrix
printf("\nInverted Matrix: A^-1\n");
printMatrix(ai);
// Product of A and A^-1
printf("\nProduct of AA^-1 Matrix\n");
printMatrix(aai);
printf("\n");
return;
}
开发者ID:davidwparker,项目名称:csci5606-numcomp,代码行数:48,代码来源:hw3.c
示例7: main
int main (int argc, char ** argv)
{
if (argc != 3)
{
printf("Use: %s <N> <T>, onde 'N' é a dimensão da matriz unitária e 'T' é o número de threads.\n", argv[0]);
return 1;
}
//Retira valores dos argumentos passados pela linha de comando
matrix_size = atoi(argv[1]);
number_of_threads = atoi(argv[2]);
//Aloca espaço para variáveis e ponteiros para colunas
A = allocateMatrix(matrix_size);
//Gera matrizes A e B
generateMatrix(A, matrix_size);
//Imprime A e B (teste)
if (matrix_size < 20)
printMatrix(A, matrix_size, "A");
//Ponteiro com threads
pthread_t * p_threads;
//Alocação de espaço para threads de acordo com o número de threads
p_threads = (pthread_t *) malloc(number_of_threads * sizeof(pthread_t));
//Inicializa o mutex
pthread_mutex_init(&mut, NULL);
//Captura tempo inicial
clock_gettime(CLOCK_MONOTONIC, &initial_time);
//Criação de threads
createThreads(p_threads, number_of_threads, matrix_size, A);
//Join das threads
joinThreads(p_threads);
//Captura tempo final
clock_gettime(CLOCK_MONOTONIC, &end_time);
//imprime resultado
printf("A soma de todos os termos é: %d\n", sum);
//Calcula tempo final
double elapsed = end_time.tv_sec - initial_time.tv_sec;
elapsed += (end_time.tv_nsec - initial_time.tv_nsec) / 1000000000.0;
printf ("O tempo de processamento foi de: %f segundos\n", elapsed);
//Inicializa o mutex
pthread_mutex_destroy(&mut);
return 0;
}
开发者ID:rprata,项目名称:sistemas-operacionais-desc,代码行数:55,代码来源:sum-matrix-pthread.c
示例8: main
int main (int argc, char * argv[]) {
int i, j, k; // loop variables
double * F, * G; // Create matrix pointers, G is verification matrix
//srand(time(NULL)); // Seed randoms
// Set size of DIM, default is 4097 from lab requirements
if (argc == 1) {
DIM = 4097;
} else {
DIM = atoi(argv[1]);
}
size_t memSize = DIM * DIM * sizeof(double);
// Allocate memory for matrices
F = (double *) malloc(memSize);
G = (double *) malloc(memSize);
if (F == NULL || G == NULL) fprintf(stderr, "Error allocating matrix\n");
// define thread hierarchy
int nblocks = NBLOCKS;
int tpb = TPB;
// initialize with randoms in range [1.0 2.0)
for (i = 0; i < DIM; i++) {
for (j = 0; j < DIM; j++) {
int temp = rand();
temp &= MASK_A;
temp |= MASK_B;
F[i * DIM + j] = *(float *) &temp;
G[i * DIM + j] = *(float *) &temp;
}
}
// Take beginning time
time_t time1 = time(NULL);
clock_t tick = clock();
// Perform matrix computations
computeMatrix(F, DIM);
// Take end time and calculate difference
time_t time2 = time(NULL);
tick = clock() - tick;
double timeDiff = difftime(time2, time1);
printf("elapsed time\t(clock): %d\n", (int) tick);
printf("elapsed time\t (time): %.0f\n", timeDiff);
printf("\ndiff: %d, total: %d\n", validateMatrix(F, G), DIM * DIM);
printMatrix(F);
return(0);
}
开发者ID:ankenman,项目名称:5441,代码行数:55,代码来源:lab4cuda.c
示例9: flipH
void flipH(int n, int m, int mat[n][m]){
int i, j, a;
for ( i = 0; i < m; i++ ) {
for ( j = 0; j < n/2; j++ ) {
a = mat[i][(m-1)-j];
mat[i][(m-1)-j] = mat[i][j];
mat[i][j] = a;
}
}
printMatrix(n, m, mat);
}
开发者ID:pakhomova,项目名称:repository,代码行数:11,代码来源:lab3.c
示例10: LOG
Void Picture::printDescription( )
{
LOG( "PART" ) << "Obraz " << SeqParams( )->getPicWidth( ) << " x " << SeqParams( )->getPicHeight( ) << std::endl;
printMatrix( itsSamplesY, SeqParams( )->getPicWidth( ), SeqParams( )->getPicHeight( ), LOG( "PART" ) );
LOG_TAB( );
for( UInt i = 0; i < itsCTUs.size( ); ++i )
{
if( itsCTUs[ i ] != nullptr ) itsCTUs[ i ]->printDescription( );
}
LOG_UNTAB( );
}
开发者ID:Kosyl,项目名称:HEVC,代码行数:11,代码来源:Picture.cpp
示例11: ecology_initialization
void ecology_initialization(ode_set *des,FILE *in){
float tmp;
time_t t;
char buff[CHAR_BUFF_SIZE];
while( fscanf(in, " %s ", buff) != EOF){
if (!strcmp(buff, "CARRYING_CAPACITY")){
//reading carrying capacity
fscanf(in,"%f ",&tmp);
carrying_capacity = tmp;
}
else if (!strcmp(buff, "INTERACTION_MATRIX")){
//identifying the type of the interaction matrix
fscanf(in, "%s ", buff);
if (!strcmp(buff,"custom")){
im = safeMatrixAlloc(dim,dim);
readMatrix(in, im, dim,dim);
time(&t);
printf("#Init random with clock seed: %d\n", (int) t);
srand(t);
}
else if (!strcmp(buff,"uniform_random")){
int seed;
fscanf(in, "%d", &seed);
srand(seed);
im = uniformRandomAlloc(dim,.7);
}
}
else if (!strcmp(buff, "DUMP")){
//identifying the dumping method
fscanf(in, "%s ", buff);
if (!strcmp(buff,"state")){
des->data_dump = &ecology_dump;
}
else if (!strcmp(buff,"full")){
des->data_dump = &ecology_full_dump;
}
}
}
time(&t);
printf("#Init random with clock seed: %d\n", (int) t);
srand(t);
generalized_simplex(dim,carrying_capacity*0.4,des->state);
//displaying the matrix
printMatrix(stdout, im, dim, dim);
fclose(in);
fflush(stdout);
}
开发者ID:egri-nagy,项目名称:dynamis,代码行数:54,代码来源:ecology.c
示例12: main
int main (void)
{
void printMatrix(int row,int col,int matrix[row][col]);
void transposeMatrix(int row, int col, int matrix[row][col], int temp[col][row]);
int matrix[3][4] = {
{1,2,3,4},
{1,2,3,4},
{5,6,7,8}
};
int temp[4][3];
printMatrix(3,4,matrix);
transposeMatrix(3,4,matrix,temp);
printMatrix(4,3,temp);
return 0;
}
开发者ID:ciphernix,项目名称:programming-in-c-3rd,代码行数:20,代码来源:c812.c
示例13: main
int main()
{
ROW_t mat[] = { { 0.0F, 0.1F },
{ 1.0F, 1.1F, 1.2F },
{ 2.0F, 2.1F, 2.2F, 2.3F } };
int nRows = sizeof(mat) / sizeof(ROW_t);
printMatrix( mat, nRows );
return 0;
}
开发者ID:dwinner,项目名称:CppAppdev,代码行数:11,代码来源:printMatrix.c
示例14: malloc
struct _matrix *perceptronLearn(float k, struct _matrix in, struct _matrix t, struct _matrix *w) {
// Declare appropriate matrices
int i, j;
MATRIX *net_j;
MATRIX *delta_w;
delta_w = malloc(sizeof(MATRIX));
memset(delta_w, 0, sizeof(MATRIX));
delta_w->rows = w->rows;
delta_w->cols = w->cols;
delta_w->values = malloc(delta_w->rows * delta_w->cols);
MATRIX *temp;
// Calculate output
net_j = perceptronOperate(in, w);
// Print output and training matrix
printf("\n\nLearn Output:\n");
printMatrix(*net_j);
printf("\n\nTraining Matrix:\n");
printMatrix(t);
// Caclulate error matrix
for (i = 0; i < w->rows; i++) {
for (j = 0; j < w->cols; j++) {
delta_w->values[j + i * w->cols] = k * (t.values[j] - net_j->values[j]) * in.values[i]; // This might go wrong
}
}
// Output error matrix
printf("\n\nDelta_W Matrix:\n");
printMatrix(*delta_w);
// Add to weight matrix, free and return
temp = matrixAdd(*w, *delta_w);
//w falues aren't changed because they are declared and handled in operator.c??
free(w);
return temp;
}
开发者ID:wbjacks,项目名称:scifi_calc,代码行数:41,代码来源:perceptron.c
示例15: printPlaceObject2
void printPlaceObject2(FILE *f, int length)
{
int start = fileOffset;
int flags = readUInt8(f);
int l;
println("Depth: %i", readUInt16(f));
if(flags & PLACE_HASMOVE)
println("Has move flag");
if(flags & PLACE_HASCHARACTER)
println("Character ID: %i", readUInt16(f));
if(flags & PLACE_HASMATRIX)
{
println("Matrix:");
printMatrix(f);
}
if(flags & PLACE_HASCXFORM)
{
print("CXForm: ");
printCXForm(f, true);
putchar('\n');
}
if(flags & PLACE_HASRATIO)
println("Ratio: %i", readUInt16(f));
if(flags & PLACE_HASNAME)
println("Name: %s", readString(f));
if(flags & PLACE_HASCLIP)
println("ClipDepth: %i", readUInt16(f));
if(flags & PLACE_RESERVED)
{
println("Mystery number: %04x", readUInt16(f));
flags = readUInt16(f);
println("Clip flags: %04x", flags);
while((flags = readUInt16(f)) != 0)
{
println("Flags: %04x", flags);
l = readUInt32(f);
decompileAction(f, l, 0);
}
}
dumpBytes(f, length-(fileOffset-start));
}
开发者ID:akleine,项目名称:libming,代码行数:53,代码来源:listswf.c
示例16: main
int main()
{
int n=7;
int M[10][10];
memset(M,0,sizeof(M));
generateMagicSquare(M, n);
printMatrix(M,n);
}
开发者ID:RAJU009F,项目名称:my-work,代码行数:12,代码来源:magicSquareMatrix.c
示例17: displayResult
/* Game Result*/
void displayResult(char box[]) {
int x=gameOver(box);
if(x==10) {
printf("Player X won\n");
} else if(x==-10) {
printf("Player O won\n");
} else {
printf("....DRAW...\n");
}
printMatrix(box);
system("pause");
}
开发者ID:jadavharsh111,项目名称:Assignments,代码行数:13,代码来源:Tic+Tac+Toe+using+MiniMax+Algorithm.cpp
示例18: makeYAxisRotation
void makeYAxisRotation(CvMat* dst, double angle)
{
setHomography(dst,
1.0, 0.0, 0.0,
0.0, cos(angle), -1*sin(angle),
0.0, sin(angle), cos(angle));
if (DEBUG) {
printf("Y: \n");
printMatrix(dst);
}
}
开发者ID:pseudonumos,项目名称:ImageBasedRenderer,代码行数:12,代码来源:main.c
示例19: TestPrintMatrix
//测试函数
void TestPrintMatrix()
{
vector<vector<int>> matrix = { {1,2,3},{5,6,7},{9,10,11},{13,14,15} };
vector<int> ret;
ret = printMatrix(matrix);
int i = 0;
while (i < ret.size())
{
cout << ret[i++] << " ";
}
cout << endl;
}
开发者ID:htyxiaoaiai,项目名称:Offer,代码行数:13,代码来源:19_printMatrix.cpp
示例20: main
int main() {
srand(time(0));
int m[N][N];
for (int row = 0; row < N; ++row) {
for (int col = 0; col < N; ++col) {
m[row][col] = (rand() % 5) - 2;
}
}
printMatrix(m);
findSubmatrixWithBiggestSum(m);
return 0;
}
开发者ID:chrzhang,项目名称:abc,代码行数:12,代码来源:main.cpp
注:本文中的printMatrix函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论