本文整理汇总了C++中printMatrix函数的典型用法代码示例。如果您正苦于以下问题:C++ printMatrix函数的具体用法?C++ printMatrix怎么用?C++ printMatrix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printMatrix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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;
}
示例5: printConsole
void Field::printAll() {
if (t > nextFrameTime) {
nextFrameTime += algo::ftr().TMax() / algo::ftr().FramesCount();
printConsole();
printViews();
printMatrix();
printTimes();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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( );
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}