Ver Mensaje Individual
  #8 (permalink)  
Antiguo 15/12/2009, 12:00
Dniel
 
Fecha de Ingreso: diciembre-2009
Mensajes: 51
Antigüedad: 15 años, 3 meses
Puntos: 1
Respuesta: Producto de matrices.

Gracias Osdiwe.

No obstante, las dos matrices aparecen iguales, es decir, los elementos que aparecen en la matriz A son los mismos que aparecen en la matriz B, una vez hecho el siguiente código:

Código PHP:
<body>
        <?php
            
echo '<h3>';echo 'Matriz A';echo '</h3>';
            echo 
"<table border=\"1\">";
            for(
$i=0;$i<$_POST['N'];$i++){
                echo 
"<tr>";
                for(
$j=0;$j<$_POST['M'];$j++){
                    echo 
"<td>";
                    
$actual $i.$j;
                    echo 
$_POST[$actual];
                    echo 
"</td>";
                }
                echo 
"</tr>";
            }
            echo 
"</table>";
            echo 
'<h3>';echo 'Matriz B';echo '</h3>';
            echo 
"<table border=\"1\">";
            for(
$i=0;$i<$_POST['M'];$i++){
                echo 
"<tr>";
                for(
$j=0;$j<$_POST['P'];$j++){
                    echo 
"<td>";
                    
$actual $i.$j;
                    echo 
$_POST[$actual];
                    echo 
"</td>";
                }
                echo 
"</tr>";
            }
            echo 
"</table>";
            echo 
'<h3>';echo 'Producto';echo '</h3>';
            for(
$i=0;$i<$elementosA;$i++){
                for(
$j=0;$j<$elementosA;$j++){
                    
$matrizC[$i][$j]=0;
                    for(
$k=0;$k<$elementosA;$k++){
                        
$matrizC[$i][$j]+=$matrizA[$i][$k]*$matrizB[$k][$j];
                    }
                }
                
$elementosC++;
            }
            echo 
"<table border=\"1\">";
            for(
$i=0;$i<$elementosC;$i++){
                echo 
"<tr>";
                for(
$j=0;$j<$elementosC;$j++){
                    echo 
"<td>";
                    echo 
$matrizC[$i][$j];
                    echo 
"</td>";
                }
                echo 
"</tr>";
            }
            echo 
"</table>";
        
?>
</body>
Y, aunque aparezcan distintos, no sé como podría realizar el producto de las mismas en un mismo bucle for.