PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 15, 2018 2:59 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to Multiply matrix?
PostPosted: Mon May 21, 2007 9:43 am 
Offline
Forum Newbie

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:09 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
You don't expect PHP to have native support for matrix multiplication, don't you?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:20 am 
Offline
Forum Newbie

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:29 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
Either write your own or search for something ready-to-use on the net.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:32 am 
Offline
Forum Newbie

Joined: Mon May 21, 2007 9:35 am
Posts: 6
Already search in google for it, but i didn't find any match code for it :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:35 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
Well, then what do you expect us to do? We aren't going to do it for you (unless you pay us :P).


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:43 am 
Offline
DevNet Resident
User avatar

Joined: Mon Aug 22, 2005 12:11 pm
Posts: 1912
Location: Leeds/Manchester, England
Why don't you show us what you've tried?

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:58 am 
Offline
Forum Newbie

Joined: Mon May 21, 2007 9:35 am
Posts: 6
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) :(

Syntax: [ Download ] [ Hide ]
<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>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:10 am 
Offline
Forum Newbie
User avatar

Joined: Fri Dec 01, 2006 1:39 am
Posts: 14
Location: India
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:14 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
kizun4 wrote:
a11*a11 = a11
a12*a12 = a12
a13*a13 = a13

:?: :? :?: :?
That's not how you multiple matrices.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:24 am 
Offline
Forum Newbie

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:28 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
You mean matrix multiplication with scalar?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:37 am 
Offline
Forum Newbie

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:43 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:50 am 
Offline
Site Administrator
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group