Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Procesos estocasticos Beta 2.0
#include <iostream> #include <vector> using namespace std; class Matrix { public: void matrixSize(int a, int b); int getColumn(); int getRow(); void showMatrix(); void fillMatrix(); vector<vector<double>> matrix; private: int column; int row; }; void Matrix::matrixSize(int b, int a) { column=a; row=b; matrix.resize(row); for(int i = 0; i < matrix.size(); i++) { matrix[i].resize(column); } } int Matrix::getColumn() { return column; } int Matrix::getRow() { return row; } void Matrix::showMatrix() { int renglonN = 1; cout << " "; for(int a = 1; a <= column; a++) { cout << " " << a << " "; }cout << endl; for(auto i:matrix) { cout << renglonN << " "; for(auto j: i) { printf("%2.3lf ", j); }cout << "\n"; renglonN++; } } void Matrix::fillMatrix() { double in; for(int i = 0; i < row; i++) { for(int j = 0; j < column; j++) { cin >> in; matrix[i][j] = in; } } } Matrix multMatrix(Matrix ma, Matrix mb) { Matrix mr; double suma; int ra = ma.getRow(); int ca = ma.getColumn(); int rb = mb.getRow(); int cb = mb.getColumn(); mr.matrixSize(ra, cb); for(int a = 0; a < ra; a++) { for(int b = 0; b < cb; b++) { suma = 0; for(int i = 0; i < ca; i++) { suma += ma.matrix[a][i]*mb.matrix[i][b]; } mr.matrix[a][b] = suma; } } return mr; } Matrix potMatrix(Matrix a, int pot) { Matrix matrixG; matrixG = a; for(int i = 0; i < pot-1; i++) { matrixG = multMatrix(matrixG, a); } return matrixG; } Matrix genMatrixPi(int n, int tam) { Matrix pi; pi.matrixSize(1,tam); for(int i = 0; i < tam; i++) { if(i != n) pi.matrix[0][i] = 0; else pi.matrix[0][i] = 1; } return pi; } double start(Matrix matrixT, int inicio, int final, int periodos) { Matrix matrixPi, matrixRes; //Si ya se que sobra una asignación pero asi lo tengo más ordenado matrixPi = genMatrixPi(inicio, matrixT.getColumn()); matrixRes = matrixPi; for(int i = 0; i < periodos; i++) { matrixRes = multMatrix(matrixRes, matrixT); cout << endl; } // cout << "\nResultado: " << matrixRes.matrix[0][final] << "\n"; /*cout << "\nPi: \n"; matrixRes.showMatrix();*/ return matrixRes.matrix[0][final]; } double firstTime(Matrix matrixT, int inicio, int final, int n) { double s, ft, ns; double res; if( n < 1 ) return 0; s = start( matrixT, inicio, final, n); cout << "Start: " << s << "\n"; ft = firstTime( matrixT, inicio, final, n-1); cout << "First time: " << ft << "\n"; ns = start( matrixT, final, final, n-1); cout << "Same start: " << ft << "\n"; res = s - ft*ns; cout << "Res: " << res << " Periodo: " << n << "\n"; return res; } int main() { Matrix matrixT, matrixR, matrixV; int tam, inicio, final, periodos; double resultado; cin >> tam; tam++; matrixT.matrixSize(tam, tam); matrixT.fillMatrix(); matrixT.showMatrix(); cin >> inicio; cin >> final; cin >> periodos; resultado = firstTime(matrixT, inicio, final, periodos); cout << resultado << "\n"; //start(matrixT, inicio, final, periodos); return 0; }
run
|
edit
|
history
|
help
0
stl_sizeof.cc
Expected GCD
MapGrocery
C++ Array printing
HeapSort
410
CPP Multi Inherit
Reverese every K node in list
Odwrócone podciągi
1