Page 1 of 2

How to Multiply matrix?

Posted: Mon May 21, 2007 9:43 am
by kizun4
Excuse me, i'm a new member in here, i'm really interesting in php programming but im a such newbie person who just know php for 4 month ^^

Wanna ask something about the matrix, how to multiply matrix in php?
for example in here : http://www.easycalculation.com/matrix/m ... cation.php

Already try to make it but it doesnt work at all.. T___T
i dont need javascript like site above, just need the normal html & php code for the calculation.. can someone help me out from this problem please..?? Thx so much before, glad to join to this forum, im a quite php freaks, but still very2 newbie.. :oops: :oops:

Posted: Mon May 21, 2007 10:09 am
by Oren
You don't expect PHP to have native support for matrix multiplication, don't you?

Posted: Mon May 21, 2007 10:20 am
by kizun4
Actually i just need the php code (matrix multiplication) for my DSS (Decision Support System) project that requires to multiply the matrix. Hope someone can help me out! :D

Posted: Mon May 21, 2007 10:29 am
by Oren
Either write your own or search for something ready-to-use on the net.

Posted: Mon May 21, 2007 10:32 am
by kizun4
Already search in google for it, but i didn't find any match code for it :(

Posted: Mon May 21, 2007 10:35 am
by Oren
Well, then what do you expect us to do? We aren't going to do it for you (unless you pay us :P).

Posted: Mon May 21, 2007 10:43 am
by jayshields
Why don't you show us what you've tried?

I can't see many places for you to go wrong in implementing this...

Posted: Mon May 21, 2007 10:58 am
by kizun4
I just can made like this :(
just normal multiplication:

a11*a11 = a11
a12*a12 = a12
a13*a13 = a13

but code above that i made is false, the multiplication matrix actually is not like that.. hiks..
this is my code (the way to multiply the matrix is false) :(

Code: Select all

<html> 

<head> 

<title>Matrix</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

</head> 

 

<body> 

<? 

if(!isset($_POST["step"])){ 

echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; 

echo "<input type='hidden' name='step' value='1'>"; 

echo "Set ordo matriks <br>"; 

echo "<input type='text' name='baris' size='3'> x <input type='text'
name='kolom' size='3'>"; 

echo "&nbsp;&nbsp;<input type='submit' value='Next'>"; 

echo "</form>"; 

} 

else{ 

$step=$_POST["step"]; 

$baris=$_POST["baris"]; 

$kolom=$_POST["kolom"]; 

	if($step==1){ 

	echo "<p>Order matrik $baris x $kolom</p>"; 

	echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; 

	echo "<input type='text' name='step' value='2'>"; 

	echo "<input type='text' name='kolom' value='$kolom'>"; 

	echo "<input type='text' name='baris' value='$baris'>";

	echo "<table cellpadding='5' boder='1'>"; 

	echo "<tr>"; 

	for($a=1;$a<=2;$a++){ 

	echo "<td>"; 

	echo "<table cellpadding='3' border='1'>"; 

		for($i=1;$i<=$baris;$i++){ 

			echo "<tr>"; 

				for ($j=1;$j<=$kolom;$j++){ 

				echo "<td><input type='text' name='$a-$i-$j' size='3'></td>"; 

				} 

			echo "</tr>"; 

		} 

	echo "</table>"; 

	echo "</td>"; 

	} 

	echo "</tr>";		 

	echo "</table>"; 

	echo "&nbsp;&nbsp;<input type='submit' value='Multiply'>"; 

	echo "</form>"; 

	} 

	if($step==2){ 

	echo "<p>Order matrik $baris x $kolom</p>"; 

	echo "<table cellpadding='5' border='1'>"; 

	echo "<tr valign='top'>"; 

	for($a=1;$a<=2;$a++){ 

	echo "<td>"; 

	echo "<table cellpadding='3' border='1'>"; 

		for($i=1;$i<=$baris;$i++){ 

			echo "<tr>"; 

				for ($j=1;$j<=$kolom;$j++){ 

				echo "<td>".$_POST[$a."-".$i."-".$j]."</td>"; 

				} 

			echo "</tr>"; 

		} 

	echo "</table>"; 

	echo "</td>"; 

	} 

	echo "<td><p>Result :</p>"; 

	echo "<table cellpadding='3' border='1'>"; 

		for($i=1;$i<=$baris;$i++){ 

			echo "<tr>"; 

				for ($j=1;$j<=$kolom;$j++){ 

				echo "<td>"; 

				echo $_POST["1-".$i."-".$j] * $_POST["2-".$i."-".$j]; 

				echo "</td>"; 

				} 

			echo "</tr>"; 

		} 

	echo "</td>"; 

	echo "</tr>";		 

	echo "</table>"; 

	} 

} 

?> 

</body> 

</html>

Posted: Mon May 21, 2007 11:10 am
by Ind007
I have a suggestion as the logic is same in any language, try to google the code written in other languages and then try to implement in PHP.

Posted: Mon May 21, 2007 11:14 am
by Oren
kizun4 wrote:a11*a11 = a11
a12*a12 = a12
a13*a13 = a13
:?: :? :?: :?
That's not how you multiple matrices.

Posted: Mon May 21, 2007 11:24 am
by kizun4
Thanks for all the advices, but i've already google for it, and couldn't find the right code for this.. T__T

@Oren:
:?: That's my way.. just a normal & single multiplication.. not a real way of multiplicationing matrix..
a11*a11 = a11
a12*a12 = a12
a13*a13 = a13

that's true.. that's my code above will works..

first you need to set how much the column.. if you set 3x3 then you will multiply matrix 3x3
if you set 5x5 then you will be able to set matrix multiplication in 5x5 columns..
but it's just a single multiplication, not the real matrix multiplication..

Posted: Mon May 21, 2007 11:28 am
by Oren
You mean matrix multiplication with scalar?

Posted: Mon May 21, 2007 11:37 am
by kizun4
I want to make like this :
http://www.easycalculation.com/matrix/m ... cation.php

the code that i made is just a single multiplication..
try to use this, it will appear how the result from http://www.easycalculation.com/matrix/m ... cation.php

Posted: Mon May 21, 2007 11:43 am
by Oren
I'm sorry, but it seems that you don't even know how to multiple 2 matrices. Please do some research and come back to us when you have a real PHP-related problem.

Posted: Mon May 21, 2007 11:50 am
by RobertGonzalez
Have a look at the logic in the matrix multiplication. Write that out on paper. Convert that to code comments. Then code your comments. Start with one dimension (say 2X2 matrix multiplication) then expand into multiple dimensions with greater/more complex matrix types.