int main()
{	 
	int i, j, matA[3][3], matB[3][3], resul[3][3], acao;
	int lin, col;
	
	printf("Matriz A 3x3\n");
	for(i = 0; i < 3; i++){
		for(j = 0; j < 3; j++){
			scanf("%d", &matA[i][j]);
		}
	}
	col = j;
	
	printf("\nMatriz B 3x3\n");
	for(i = 0; i < 3; i++){
		for(j = 0; j < 3; j++){
			scanf("%d", &matB[i][j]);
		}
	}
	lin = i;
		
	printf("\nEscolha 1 para somar ou 2 para multiplicar: ");
	scanf("%d", &acao);
	
	//if para comar ou multiplicar as matrizes A e B
	if(acao == 1){ //Complexidade n2
		for(i = 0; i < 3; i++){
			for(j = 0; j < 3; j++){
				resul[i][j] = matA[i][j] + matB[i][j];
			}
		}
		matriz(resul);
	}else if(acao == 2){  // Complexidade n3
		if(lin == col){ //Verifica se é possivel calcular o produto da matriz...
		   	int d;
			for(i = 0; i < 3; i++){
				for(j = 0; j < 3; j++){
					resul[i][j] = 0;
					for(d = 0; d < 3; d++){
						resul[i][j] = resul[i][j] + matA[i][d] * matB[d][j];
					}
				}
			}
			matriz(resul);
		}else{
			printf("Não é possivel calcular o produtos das matrizes\n");
		}
	}
		
	return 0;
}
Exemplo n.º 2
0
int main(int argc,char **argv){

  /*
    LÓGICA DO ALGORÍTIMO USADO: http://mathfaculty.fullerton.edu/mathews/n2003/HouseholderMod.html

    c++ Householder1.cpp -o Householder1 Householder2.cpp -o Householder2 Main.cpp -o Main
    ./Main Matrix.txt

  */

  if(argc<2){
    printf("NÚMERO DE PARÂMETROS INVÁLIDOS, POR FAVOR ENTRE COM O NOME DO ARQUIVO COM A MATRIX\n");
    printf("%s\n", "EX: ./Main Matrix.txt");
    printf("%s\n%s\n%s\n", "PARA RODAR O PROGRAMA CORRETAMENTE:",
    "c++ Householder1.cpp -o Householder1 Householder2.cpp -o Householder2 Main.cpp -o Main",
    "./Main Matrix.txt");
    exit(0);
  }
  FILE *arq;
  //FILE *arq_saida;
  arq = fopen(argv[1],"r");
  //arq_saida = fopen(argv[2],"w");

  matriz *m;
  m = (matriz*)malloc(sizeof(matriz));
  Householder matriz(m,arq);
  matriz.run();
  fclose(arq);
  //fclose(arq_saida);

  return EXIT_SUCCESS;
}
Exemplo n.º 3
0
bool Tablero::ganar(QString ip)
{
    MatrizEnTripletas matriz(3,3);
    for (int i = 1; i <= _tablero.numeroElementos(); i++)
    {
	Tripleta tripleta = _tablero.tripleta(i);
	if (tripleta.ip() == ip)
	{
	    matriz.insertaTripleta(tripleta);
	}
    }
    if (matriz.numeroElementos() < 3)
	return false;
    bool triqui = false;
    int cons = matriz.tripleta(1).columna();
    for(int i = 1; i <= matriz.numeroElementos(); i++)
    {
	Tripleta tripleta = matriz.tripleta(i);
	if(tripleta.fila() == i && tripleta.columna() == cons)
	    triqui = true;
	else
	    triqui = false;
    }
    if (triqui)
	return triqui;
    cons = matriz.tripleta(1).fila();
    for (int i = 1; i <= matriz.numeroElementos(); i++)
    {
	Tripleta tripleta = matriz.tripleta(i);
	if (tripleta.columna() == i && tripleta.fila() == cons)
	    triqui = true;
	else
	    triqui = false;
    }
    if (triqui)
	return triqui;
    for (int i = 1; i <= matriz.numeroElementos(); i++)
    {
	Tripleta tripleta = matriz.tripleta(i);
	if (tripleta.columna() == tripleta.fila())
	    triqui = true;
	else
	    triqui = false;
    }
    if (triqui)
	return triqui;
    for (int i = 1; i <= matriz.numeroElementos(); i++)
    {
	Tripleta tripleta = matriz.tripleta(i);
	if (tripleta.fila() == i && tripleta.columna() == matriz.numeroElementos() + 1 - i)
	    triqui = true;
	else
	    triqui = false;
    }
    return triqui;
}
Exemplo n.º 4
0
void Malla::dibuja(Modo modo)
{
    glPushMatrix();
    glMultMatrixd(matriz().getMatrizAfin());
    foreach (const Cara &c, m_caras) {
      glColor3f(m_color.r, m_color.g, m_color.b);
        if (modo == Solido){
	  c.dibuja(Cara::Solid);
	} else {
	  c.dibuja(Cara::Wireframe);
	}
    }
Exemplo n.º 5
0
int main(int argc, char **argv)
{
  float *a_walk;
  float *b_walk;
  float *c_walk;
  float *d_walk;
  float *l_walk;
  float *yInicial;
  float *yDelMomento;
  float *yCandidato;
  float *x_obs;
  float *y_obs;
  int n_puntos;
  int iteraciones;
  int i;
  int burn;

  iteraciones = atoi(argv[1]);
  burn = atoi(argv[2]);
  n_puntos = 1995-1800+1;

  x_obs = matriz(n_puntos);
  y_obs = matriz(n_puntos);
  a_walk = matriz(iteraciones);
  b_walk = matriz(iteraciones);
  c_walk = matriz(iteraciones);
  d_walk = matriz(iteraciones);
  yInicial = matriz(n_puntos);
  yDelMomento = matriz(n_puntos);
  yCandidato = matriz(n_puntos);
  l_walk = matriz(iteraciones);



  sacarLosDatos(y_obs);

  estadoInicial(a_walk, b_walk, c_walk, d_walk, l_walk, yInicial, x_obs, y_obs, n_puntos);

  elCamino(x_obs, y_obs, yDelMomento,yCandidato, a_walk, b_walk, c_walk, d_walk, l_walk, n_puntos, iteraciones, burn);
}
int main(){
    VetorBi *m= matriz(9,9); 
    
    int i,j; 
    
    atribuirValores(m);
    
    printf("Sudoku\n\n");
    imprimirMatriz(m);

    desalocar(m); 
    system("pause");
    return 0; 
}
Exemplo n.º 7
0
void VectorSpaceModel::llenarMatrizConTFIDF() {
listaD::iterator interno;
mapaDelDiccionario::iterator externo;

for (externo = miDiccionario->diccionario.begin(); externo != miDiccionario->diccionario.end();
			externo++) {
	int posicionPalabra = bbinaria(externo->first); //busca la posicion del token
	if (posicionPalabra != -1){
		for (interno=externo->second.begin(); interno != externo->second.end(); interno++){
			TipoGuardado idf = palabras[posicionPalabra].idf;
			int ft = interno->second.getFrecuencia();
			matriz(interno->first,posicionPalabra)= (TipoGuardado) ft * idf;
			}
		}
	}
}
Exemplo n.º 8
0
//===================================================================//
double InterpolationLinearSystem(double *x,double *y, int N, double t){
	//if (x != xAnterior || y != yAnterior){
		Matriz matriz(N,2);
		for (int c = 0 ; c < N ; c++){
			matriz.setElemento(c,0,x[c]);
			matriz.setElemento(c,1,y[c]);
		}
		matriz.interpolar(&polinomio);
		cout << endl << "Polinômio pela Forma Linear: ";
		polinomio->imprimir();
		cout << endl;
		//xAnterior = x ,yAnterior = y;
	//}

	return polinomio->getValor(t);
}
Exemplo n.º 9
0
void VectorSpaceModel::limpiarMatriz(){
	for (unsigned i = 0; i<cantDocs; i++)
		for (unsigned j = 0; j<cantTerminos; j++)
			matriz(i,j) = 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
  float *a_walk;
  float *b_walk;
  float *c_walk;
  float *d_walk;
  float *l_walk;
  float *yInicial;
  float *xDelMomento;
  float *xCandidato;
  float *x_aComparar;
  float *y_ayudaAx;
  float *x_obs;
  float *y_obs;
  float *x;
  float *y;
  int n_puntos;
  int iteraciones;
  int i;
  int burn;
  float x_0,y_0;
  float paso;

  iteraciones = atoi(argv[1]);
  burn = atoi(argv[2]);
  n_puntos = 96;
  paso = 0.8/n_puntos;

  x = matriz(n_puntos);
  y = matriz(n_puntos);
  x_obs = matriz(n_puntos);
  y_obs = matriz(n_puntos);
  a_walk = matriz(iteraciones);
  b_walk = matriz(iteraciones);
  c_walk = matriz(iteraciones);
  d_walk = matriz(iteraciones);
  yInicial = matriz(n_puntos);
  xDelMomento = matriz(n_puntos);
  xCandidato = matriz(n_puntos);
  l_walk = matriz(iteraciones);
  x_aComparar = matriz(n_puntos);
  y_ayudaAx = matriz(n_puntos);



  sacarLosDatos(x_obs, y_obs);

  x_0 = x_obs[0];
  y_0 = y_obs[0];

  estadoInicial(a_walk, b_walk, c_walk, d_walk, l_walk, yInicial, x_obs, x, y, n_puntos, y_0, x_0, paso);

  elCamino(x_obs, x_aComparar, y_ayudaAx, xDelMomento, xCandidato, a_walk, b_walk, c_walk, d_walk, l_walk, paso, n_puntos, iteraciones, burn);
}