Search This Blog

Saturday, March 31, 2012

Easy algorithm in C++ to treat random data.


Given a binary sequence, the following algorithm counts how many voltage increases there are in a certain period of time.

Note: let 1 be a tiny voltage increase and 0 a constant voltage. Somehow (at present I don’t know how to do it), real data ought to be correctly processed so as to get a real analysis of what is happening in the quantum scale; in order not to complicate this algorithm, let’s suppose a random database created in Excel, for instance.
----------------------------------------------------------------------------------------------------------
#include <iostream>
#include <math.h>

using namespace std;

void main (void)
{
            int i,j,var1,var2cont1,cont2,nrows,ncolumns,totaldata,percent1,percent2;
            int matrix[1000][1000];

  cout<<”(Please copy and paste the binary sequence considered in a certain period of time and type  it as a matrix)”<<endl;

  cout<<”Type the number of rows :”<<endl;
  cin>>nrows;
  cout<<”Type the number of columns :”<<endl;
  cin>>ncolumns;

  for (i=0;i<nrows;i++)
  {
              for (j=0;j<ncolumns;j++)
              {
                          cout<<”Type element [i+1][j+1]: “<<endl;
                          cin>>matrix[i][j];
              }
  }
  cout<<”Input matrix: “<<endl;
  for (i=0;i<nrows;i++)
  {
              for (j=0;j<ncolumns;j++)
              {
                          cout<<matrix[i][j]<<” “;
              }
              cout<<endl;
  }





var1=0;
var2=0;
for (i=0;i<nrows;i++)
{
            for (j=0;j<ncolumns;j++)
            {
                       if (matrix[i][j]==1)
                                   {
                                               var1++;
                                   }
                       else
                                   {
                                               var2++;
                                   }
            }  cont1=var1;
                cont2=var2;        
}


            totaldata=nrows*ncolumns;

            int a=cont1/totaldata;
            percent1=a*100;

            int b=cont2/totaldata;
            percent2=b*100;

            cout<<”Conclusion: “<<percent1<< ” % of times seems to have been a voltage increase, whereas  
“ << percent2 << ” % of times it’s very likely to have been a constant voltage.” <<endl;

            system (“pause”);

}

No comments:

Post a Comment