Foros del Web » Programación para mayores de 30 ;) » Java »

Problema en multiplicación de matrices

Estas en el tema de Problema en multiplicación de matrices en el foro de Java en Foros del Web. void jBtnMulti_actionPerformed(ActionEvent e) { int x,y,xr,yr; int FA = Integer.parseInt(TxTFA.getText()); int CA = Integer.parseInt(TxTCA.getText()); int FB = Integer.parseInt(TxTFB.getText()); int CB = Integer.parseInt(TxTCB.getText()); if ( (CA ...
  #1 (permalink)  
Antiguo 28/08/2008, 15:55
 
Fecha de Ingreso: agosto-2008
Mensajes: 11
Antigüedad: 15 años, 8 meses
Puntos: 0
Problema en multiplicación de matrices

void jBtnMulti_actionPerformed(ActionEvent e) {
int x,y,xr,yr;
int FA = Integer.parseInt(TxTFA.getText());
int CA = Integer.parseInt(TxTCA.getText());
int FB = Integer.parseInt(TxTFB.getText());
int CB = Integer.parseInt(TxTCB.getText());
if ( (CA == FB) && (FA == CB)) {
MR.setColumnCount(CA);
MR.setRowCount(FB);
for(x=0;x<CA;x++)
for(y=0;y<FB;y++)
{
Integer MAR = new Integer (MA.getValueAt(x,y).toString());
Integer MBR = new Integer (MB.getValueAt(x,y).toString());
Integer Val = new Integer (MAR.intValue() * MBR.intValue());
MR.setValueAt(Val, x, y);
}

}
else
JOptionPane.showMessageDialog(this,"Error en las dimensiones de las matrices","Error",JOptionPane.YES_OPTION);

}

ESE ES MI CÓDIGO DE UNA MULTIPLICACIÓN DE MATRICES... PERO A LA HORA DE EJECULTARLO ME SALEN TODOS ESTOS ERRORES.. ALGUIEN PODRIA AYUDARME
matrices.MatricesApp
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2

at java.util.Vector.elementAt(Vector.java:431)

at javax.swing.table.DefaultTableModel.getValueAt(Def aultTableModel.java:617)

at matrices.Matriz.jBtnMulti_actionPerformed(Matriz.j ava:230)

at matrices.Matriz_jBtnMulti_actionAdapter.actionPerf ormed(Matriz.java:329)

at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.jav a:5100)

at java.awt.Component.processEvent(Component.java:489 7)

at java.awt.Container.processEvent(Container.java:156 9)

at java.awt.Component.dispatchEventImpl(Component.jav a:3615)

at java.awt.Container.dispatchEventImpl(Container.jav a:1627)

at java.awt.Component.dispatchEvent(Component.java:34 77)

at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3128)

at java.awt.Container.dispatchEventImpl(Container.jav a:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606 )

at java.awt.Component.dispatchEvent(Component.java:34 77)

at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)

at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100)
  #2 (permalink)  
Antiguo 28/08/2008, 22:14
 
Fecha de Ingreso: diciembre-2006
Mensajes: 127
Antigüedad: 17 años, 4 meses
Puntos: 1
Información Respuesta: Problema en multiplicación de matrices

Hola liymsr Creo que tienes mal tu programa!!....que tamaño son las matrices??

Te puedo orientar si gustas saludos
  #3 (permalink)  
Antiguo 29/08/2008, 07:09
 
Fecha de Ingreso: agosto-2008
Mensajes: 11
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Problema en multiplicación de matrices

Hola Abulon muchas gracias por tu ayuda... el tamaño de las matrices son ingresadas por el usuario.. lo que pasa es que un programa que hace la suma, resta y multiplicación de matrices.. la suma y resta ya me quedaron, la multi es lo que mes está dando problemas.... aqui te dejo el código completo!! en verdad agradeceria mucho tu ayuda!! .. gracias


Código PHP:
 void jButton1_actionPerformed(ActionEvent e) {
    
MA.setColumnCount(Integer.parseInt(TxTCA.getText()));
    
MA.setRowCount(Integer.parseInt(TxTFA.getText()));
  }

  
void jButton2_actionPerformed(ActionEvent e) {
    
MB.setColumnCount(Integer.parseInt(TxTCB.getText()));
    
MB.setRowCount(Integer.parseInt(TxTFB.getText()));
  }

  
void jBtnSuma_actionPerformed(ActionEvent e) {
    
int x,y,xr,yr;
    
int FA Integer.parseInt(TxTFA.getText());
    
int CA Integer.parseInt(TxTCA.getText());
    
int FB Integer.parseInt(TxTFB.getText());
    
int CB Integer.parseInt(TxTCB.getText());
    if ( (
CA == CB) && (FA == FB)) {
      
MR.setColumnCount(CA);
      
MR.setRowCount(FA);
      for(
x=0;x<FA;x++)
          for(
y=0;y<CA;y++)
          {
            
Integer MAR = new Integer (MA.getValueAt(x,y).toString());
            
Integer MBR = new Integer (MB.getValueAt(x,y).toString());
            
Integer Val = new Integer (MAR.intValue() + MBR.intValue());
            
MR.setValueAt(Valxy);
          }

    }
    else
      
JOptionPane.showMessageDialog(this,"Error en las dimensiones de las matrices","Error",JOptionPane.YES_OPTION);
  }

  
void jBtnResta_actionPerformed(ActionEvent e) {
    
int x,y,xr,yr;
       
int FA Integer.parseInt(TxTFA.getText());
       
int CA Integer.parseInt(TxTCA.getText());
       
int FB Integer.parseInt(TxTFB.getText());
       
int CB Integer.parseInt(TxTCB.getText());
       if ( (
CA == CB) && (FA == FB)) {
         
MR.setColumnCount(CA);
         
MR.setRowCount(FA);
         for(
x=0;x<FA;x++)
             for(
y=0;y<CA;y++)
             {
               
Integer MAR = new Integer (MA.getValueAt(x,y).toString());
               
Integer MBR = new Integer (MB.getValueAt(x,y).toString());
               
Integer Val = new Integer (MAR.intValue() - MBR.intValue());
               
MR.setValueAt(Valxy);
             }

       }
       else
         
JOptionPane.showMessageDialog(this,"Error en las dimensiones de las matrices","Error",JOptionPane.YES_OPTION);
     }

  
void TxTCB_actionPerformed(ActionEvent e) {

  }

  
void jBtnSalir_actionPerformed(ActionEvent e) {
    
System.exit(1);
  }

  
void jBtnMulti_actionPerformed(ActionEvent e) {
    
int x,y,xr,yr;
          
int FA Integer.parseInt(TxTFA.getText());
          
int CA Integer.parseInt(TxTCA.getText());
          
int FB Integer.parseInt(TxTFB.getText());
          
int CB Integer.parseInt(TxTCB.getText());
          if ( (
CA == FB) && (FA == CB)) {
            
MR.setColumnCount(CA);
            
MR.setRowCount(FB);
            for(
x=0;x<CA;x++)
                for(
y=0;y<FB;y++)
                {
                  
Integer MAR = new Integer (MA.getValueAt(x,y).toString());
                  
Integer MBR = new Integer (MB.getValueAt(x,y).toString());
                  
Integer Val = new Integer (MAR.intValue() * MBR.intValue());
                  
MR.setValueAt(Valxy);
                }

          }
          else
            
JOptionPane.showMessageDialog(this,"Error en las dimensiones de las matrices","Error",JOptionPane.YES_OPTION);

  }

  } 
  #4 (permalink)  
Antiguo 29/08/2008, 14:37
 
Fecha de Ingreso: diciembre-2006
Mensajes: 127
Antigüedad: 17 años, 4 meses
Puntos: 1
Respuesta: Problema en multiplicación de matrices

Como introduces los valores de la matriz, por que usas setColumn acaso es un metodo que implementaste??....lo estas haciendo con GUI?
  #5 (permalink)  
Antiguo 29/08/2008, 18:51
 
Fecha de Ingreso: agosto-2008
Mensajes: 11
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Problema en multiplicación de matrices

Cita:
Iniciado por abulon Ver Mensaje
como introduces los valores de la matriz, por que usas setcolumn acaso es un metodo que implementaste??....lo estas haciendo con gui?
sii es un metodo el que impletenté!! E igual lo estoy haciendo con interfaz gráfica
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:58.