How to Multiply matrix?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

How to Multiply matrix?

Post 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:
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You don't expect PHP to have native support for matrix multiplication, don't you?
kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Either write your own or search for something ready-to-use on the net.
kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

Post by kizun4 »

Already search in google for it, but i didn't find any match code for it :(
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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).
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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...
kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

Post 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>
User avatar
Ind007
Forum Newbie
Posts: 14
Joined: Fri Dec 01, 2006 12:39 am
Location: India

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

kizun4 wrote:a11*a11 = a11
a12*a12 = a12
a13*a13 = a13
:?: :? :?: :?
That's not how you multiple matrices.
kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

Post 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..
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You mean matrix multiplication with scalar?
kizun4
Forum Newbie
Posts: 6
Joined: Mon May 21, 2007 9:35 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply