1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Spanning matrices in c++

  1. Jul 20, 2008 #1
    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 seperate 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.
     
  2. jcsd
  3. Jul 21, 2008 #2

    nvn

    User Avatar
    Science Advisor
    Homework Helper

    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 (Text):
    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";
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Spanning matrices in c++
  1. Singular matrices (Replies: 3)

  2. C++ . (Replies: 19)

Loading...