elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Multiplicaciones de matrices
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Multiplicaciones de matrices  (Leído 5,352 veces)
legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Multiplicaciones de matrices
« en: 18 Diciembre 2011, 19:43 pm »

Buenas a todos y disculpen la molestia, la verdad es que me eh estado partiendo el coco con unos dilemas en PHP... me han encargado hacer un programa que me resuelva suma,resta,multiplicacion de matrices y aparte pueda sacar la transpuesta, ya eh logrado hacer que me haga la suma y la resta de matrices, tambien eh losgrado que me saque la transpuesta de una matriz, pero no logro captar como hacer la multiplicacion de matrices... sera que puedan ayudarme?

de antemano gracias

 :rolleyes: :rolleyes:


« Última modificación: 23 Diciembre 2011, 04:34 am por legomanticore » En línea

AckeR

Desconectado Desconectado

Mensajes: 109


Tu única Limitación Es tú Imaginación (:


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #1 en: 18 Diciembre 2011, 21:06 pm »

Podrías adjuntar el código que ya llevas hecho ;) y recuerda usar la etiquta GeSHi para ver mejor el code  ::)


En línea


...DaR LaS GraCiaS No CuestA NadA...
legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #2 en: 19 Diciembre 2011, 04:54 am »

ahora mismo subo lo que llevo hecho aki dejo el codigo lo hiba a subir a megaupload pero no le vi sentido a q esperaras un rato para bajar un archivo de 4 kb ... perdona la molestia y q se vea todo raro esk soy nuevo en esto del uso de GeSHi >_______<  y pss bueno ahi esta el codigo lo tengo en 4 partes distintas

la pagina lleva esto:

Código:
-----[b]libreria[/b]---------

<html>
<?php

function genera_matriz($filas,$columnas,$indice)
{
$x=1;
while ($x <= $filas)
{
$y=1;
 while ($y <= $columnas)
{
echo "<input type=text size=2 name="."'$indice$x$y'"."/>";
  $y++;
}
echo "<br>";
 $x++;
}
echo "<br>";
}
       ?>
</html>

----------[b]Main[/b]----------

<html>

<body bgcolor="blue">
<font face="arial" size="5">Proyecto Matriz!!</font>
  
  <br>
  <br>
   <font color="blue" face="arial">
  
  <iframe name="uno" width="70%" height="100%" src="problema.php" frameborder="1"
  scrolling="no" align="top">  </iframe>
 
  <iframe name="dos" width="30%" height="100%" src="resultado.php" frameborder="1"
  scrolling="no" align="top" marginheight="0" marginwidth="0">
 </iframe>
 </font>
  
</body>

</html>

-------[b]Problema[/b]---------

<?php session_start(); ?>
<html>
<body bgcolor="blue">

<font face="Tahoma" size="4">
<marquee><center>Seleccione la operacion que desea realizar</center></marquee>
</font>

<form target="uno" action="problema.php" method="post">
<font face="Tahoma" size="3">
Operación a realizar:
<select name="operacion">
<option> suma </option>
<option> resta </option>
<option> multiplicacion </option>
<option> transpuesta </option>
</select>
<br>
<input TYPE="submit" value="Captura matriz"/>
</font>
</form>

  <?php
   if (isset($_REQUEST["operacion"]))
   {
   $_SESSION["operacion"] = $_REQUEST["operacion"];
  
   if (($_REQUEST["operacion"]=="suma")or( $_REQUEST["operacion"]=="resta") or ( $_REQUEST["operacion"]=="multiplicacion"))   { $captura=2;}

 if  ($_REQUEST["operacion"]=="transpuesta") {  $captura=1;}
 
 echo "<form target=uno action=problema.php method=post>";
 $x=0;
 echo "<font face=Tahoma size=3>";
 while ($captura>$x)
 {
 $x++;
   echo "filas $x:";
   echo "<br>";
   echo "<input TYPE=text name="."'f$x'"."/>";
 echo "<br>";
   echo "columnas $x:";
   echo "<br>";
   echo "<input TYPE=text name="."'c$x'"."/>";
   echo "<br>";
 
 }
 echo "</font>";

   echo "<BR><BR><input TYPE=submit value="."'capturar valores de matriz'".">";
 echo "</form>";
   }

?>

<?php
/* Llamado a librería que genera los inputs para captura de datos de matriz */
include 'libreria.php';

if ((isset($_REQUEST["f1"]))or(isset($_REQUEST["c1"])))
{
/*Almacenar dimensiones para utilizarlas posteriormente en el calculo solicitado*/

$_SESSION["f1"]=$_REQUEST["f1"];
$_SESSION["c1"]=$_REQUEST["c1"];

echo "<form target=dos action=resultado.php method=post>";
 
/* Llamada a la función existente en la librería*/

                   genera_matriz($_REQUEST["f1"],$_REQUEST["c1"],"I");


if ((isset($_REQUEST["f2"]))and(isset($_REQUEST["c2"])))
{
/*Almacenar dimensiones para utilizarlas posteriormente en el calculo solicitado*/

$_SESSION["f2"]=$_REQUEST["f2"];
$_SESSION["c2"]=$_REQUEST["c2"];
 
/* Llamada a la función existente en la librería*/

genera_matriz($_REQUEST["f2"],$_REQUEST["c2"],"J");

}
echo "<input TYPE=submit value="."'resolver matriz'".">";
echo "</form>";
}
?>

</body>

</html>


----------[b]Resultado[/b]----------

<?php session_start()?>
<html>
<body bgcolor="blue">
               <center>
<font face="arial" size="2">
<br>
<b>Resultado del problema</b>
 <?php

  If (isset($_REQUEST["I11"]))
  {
  /* Se realiza calculo de matrices dependiendo de la operación seleccionada */  
 
If ($_SESSION["operacion"]=="suma")
  {
  $x=1;
  $y=1;
  while ($x <= $_SESSION["f1"])
  {
  while ($y <= $_SESSION["c1"])
  {
  echo "<br>";
  $matriz_resultado["$x$y"] = $_REQUEST["I$x$y"]+$_REQUEST["J$x$y"];
  $y++;
  }
  $y=1;
  $x++;
 
  }
  }

If ((isset($_REQUEST["I11"]))and(isset($_REQUEST["J11"])))
  {
  /* Se realiza calculo de matrices dependiendo de la operación seleccionada */
 
  If ($_SESSION["operacion"]=="resta")
  {
  $x=1;
  $y=1;
  while ($x <= $_SESSION["f1"])
  {
  while ($y <= $_SESSION["c1"])
  {
  echo "<br>";
  $matriz_resultado["$x$y"] = $_REQUEST["I$x$y"]-$_REQUEST["J$x$y"];
  $y++;
  }
  $y=1;
  $x++;
 
  }
  }
  }
  If (isset($_REQUEST["I11"]))
  {
  If ($_SESSION["operacion"]=="transpuesta")
 
  {
  $x=1;
  $y=1;
  while ($x <= $_SESSION["f1"])
  {
  while ($y <= $_SESSION["c1"])
  {
  $matriz_resultado["$x$y"] = $_REQUEST["I$y$x"];
 
 
  $y++;
  }
  $y=1;
  $x++;
  }
  }
  }
 
  $x=1;
  $y=1;
 
  echo "<br><br>";
  echo "<table border=1 >";
  while ($x <= $_SESSION["f1"])
  {
       echo "<tr height=50 width=50>";
  while ($y <= $_SESSION["c1"])
  {
         echo "<td height=50 width=50>";
  echo "<center>";
  echo $matriz_resultado["$x$y"] ;
  echo "</center>";
  $y++;
  echo "</td>";
  }
  $y=1;
  $x++;
  echo "</tr>";
  }
  echo "</table>";
  }
   ?>
   </font>
</center>
</body>
</html>
« Última modificación: 20 Diciembre 2011, 18:57 pm por legomanticore » En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Multiplicaciones de matrices
« Respuesta #3 en: 19 Diciembre 2011, 05:18 am »

Tienes que saber primero como se multiplican las matrices, saca la lógica y la formula y será mucho más fácil programarlo.
:http://es.wikipedia.org/wiki/Multiplicaci%C3%B3n_de_matrices
En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #4 en: 19 Diciembre 2011, 05:21 am »


de hecho si se como multiplicar matrices xD hasta sacar transpuesta e inversa y todo ese rollo :3

pero graxie :3
En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Multiplicaciones de matrices
« Respuesta #5 en: 19 Diciembre 2011, 10:40 am »

Entonces cual es tu problema?
En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #6 en: 19 Diciembre 2011, 19:48 pm »


que no entiendo bien el como hacer el codigo, la verdad ... lo eh intentado de varias formas y no me sale... :/  :-(
En línea

legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #7 en: 20 Diciembre 2011, 03:50 am »

Podrías adjuntar el código que ya llevas hecho ;) y recuerda usar la etiquta GeSHi para ver mejor el code  ::)

crees k puedas ayudarme bro? =(
En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Multiplicaciones de matrices
« Respuesta #8 en: 20 Diciembre 2011, 05:04 am »

El código lo hice apartir de este en Java, :http://www.microplagio.com/articulos/script-multiplicacion-de-matrices-en-java/
Código
  1.    class Matriz{
  2.  
  3.        function multiplicacion( $Mat1, $Mat2 ){
  4.            $suma = 0;
  5.            $result = array();
  6.            for( $i=0; $i<count($Mat1); $i++ ){
  7.                for( $j=0; $j<count($Mat2); $j++ ){
  8.                    $suma = 0;
  9.                    for( $k=0; $k<count($Mat2); $k++ ){
  10.                        $suma += $Mat1[$i][$k] * $Mat2[$k][$j];
  11.                    }
  12.                    $result[$i][$j] = $suma;
  13.                }
  14.            }
  15.            return $result;
  16.        }
  17.  
  18.        function mostrar( $Mat ){
  19.            for( $i=0; $i<count($Mat); $i++ ){
  20.                for( $j=0; $j<count($Mat[$i]); $j++ ){
  21.                    print $Mat[$i][$j]." | ";
  22.                }
  23.                print "<br/>";
  24.            }
  25.        }
  26.    }
  27.  
  28.    $Mat1[0] = array(1, 2, 3, 4);
  29.    $Mat1[1] = array(5, 6, 7, 8);
  30.  
  31.    $Mat2[0] = array(1, 2, 3, 4);
  32.    $Mat2[1] = array(5, 6, 7, 8);
  33.  
  34.  
  35.    $Matriz = new Matriz();
  36.    $Mat = $Matriz->multiplicacion($Mat1, $Mat2);
  37.    $Matriz->mostrar($Mat);
En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
legomanticore

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Multiplicaciones de matrices
« Respuesta #9 en: 20 Diciembre 2011, 06:16 am »


okz gracias :D ahora me toca colocarlo como debe para que jale con las otras 3 funciones k ia tengo ^_^
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
un problema de matrices
Programación Visual Basic
ZifuSka 3 1,702 Último mensaje 24 Octubre 2005, 05:35 am
por ZifuSka
creando Matrices en.NET
.NET (C#, VB.NET, ASP)
istrokke 2 2,817 Último mensaje 24 Febrero 2009, 23:01 pm
por bitarray
matrices en C#
Programación General
volterra 4 10,182 Último mensaje 18 Mayo 2010, 06:26 am
por Og.
matrices
Programación C/C++
aral90 2 2,240 Último mensaje 9 Diciembre 2011, 20:13 pm
por aral90
Programa que calcule multiplicaciones ASM
ASM
tete55 8 4,444 Último mensaje 6 Diciembre 2014, 19:31 pm
por x64core
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines