How to Simulate and Track the Evolution of a 128x128 Matrix in C++?

In summary, in this conversation, the speaker discusses generating a 128x128 matrix with a filling probability of 0.8 using a random seed of 1.0. The matrix is saved as a square matrix in a text file with tab delimited columns and newline as row terminator. Each iteration is saved as a separate file with the iteration number as its filename. The speaker also mentions a possible method for showing the reduction of the spanning matrix.
  • #1
chey
1
0
1. Show the evolution/reduction of the system of a 128x128 matrix with a random seed of (1.0) and
with the filling probability of 0.8. Save as a square matrix in a text file(*.txt) that has tab delimited
columns and uses newline as row terminator. Save each iteration as a separate file with the iteration
number as its filename


3. #include<iostream>
#include<fstream>
#include<time.h>

using namespace std;

int main()
{
srand(1.0);
float P1, P0, P;
int c = 128;
int array [c][c];
for(int i=0;i<c;i++)
{
for(int j=0;j<c;j++)
{
P1 = float((rand()%100)*0.01);
P0 = 0.2;
if (P1>P0)
{
P = 1;
}
else
{
P = 0;
}
array [j] = P;
}
}
ofstream out;
out.open ("try1.txt");
for(int i=0;i<c;i++)
{
for(int j=0;j<c;j++)
{
out<<array[j]<<"\t";
}
out << "\n";
}
system("pause");
return 0;
}


I was able to generate a 128x128 matrix with filling probability 0.8 but I don't know how to show the reduction of the spanning matrix.
 
Physics news on Phys.org
  • #2
This is a guess, but maybe it means, replace your line for(int j=0;j<c;j++)out<<array[j]<<"\t";, in the above post, with something like the following.

Code:
n1=0;
for(int j=0;j<c;j++){
   if(array[i][j]==1)n1=n1+1;else{
      if(n1>0)out<<n1<<"\t";
      out<<"0";
      if(j<c-1)out<<"\t";
      n1=0;
      }
   }
if(n1>0)out<<n1;
out<<"\n";
 
  • #3
Can you provide more information or context about the system and the desired outcome? The current code simply generates a random matrix with a given filling probability and saves it as a text file.
 

What is a matrix in c++?

A matrix in c++ is a data structure that stores elements in a two-dimensional grid. It is a collection of rows and columns, and can be used to represent mathematical matrices, tables, or grids of data.

How do you create a matrix in c++?

A matrix in c++ can be created using arrays or vectors. Arrays are a fixed-size collection of elements, while vectors are dynamic and can change size. Both can be used to create a two-dimensional grid, with rows and columns representing the dimensions of the matrix.

How do you access elements in a matrix in c++?

Elements in a matrix can be accessed using their row and column indices. The first element in a matrix has an index of (0,0), and the last element has an index of (n-1, m-1), where n is the number of rows and m is the number of columns in the matrix.

What is spanning a matrix in c++?

Spanning a matrix in c++ means finding a set of vectors that can be combined to create all the other vectors in the matrix. This can be useful in linear algebra and machine learning, where finding a set of independent vectors that span a larger space can be helpful in solving problems.

How can spanning a matrix be implemented in c++?

Spanning a matrix in c++ can be implemented using various algorithms such as Gaussian Elimination, Gram-Schmidt process, or Singular Value Decomposition. These algorithms involve manipulating the matrix and its elements to find a set of independent vectors that span the matrix.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
23
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
25
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top