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

  • Thread starter Thread starter chey
  • Start date Start date
  • Tags Tags
    C++ Matrices
AI Thread Summary
The discussion focuses on simulating and tracking the evolution of a 128x128 matrix in C++ with a filling probability of 0.8, using a random seed of 1.0. Participants share code snippets to generate the matrix and save it as a tab-delimited text file. While the initial code successfully creates the matrix, there is uncertainty about how to represent the reduction of the spanning matrix in the output. A proposed solution involves modifying the output logic to count consecutive ones and represent them accordingly. The conversation emphasizes the importance of correctly formatting the output for each iteration of the matrix.
chey
Messages
1
Reaction score
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
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";
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
23
Views
8K
Replies
2
Views
2K
Replies
15
Views
2K
Replies
2
Views
6K
Replies
3
Views
2K
Replies
13
Views
3K
Replies
3
Views
1K
Replies
9
Views
3K
Replies
4
Views
1K
Back
Top