PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 15, 2020 2:20 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Mon May 21, 2007 12:41 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 1:14 pm 
Offline
Site Administrator
User avatar

Joined: Tue Sep 09, 2003 6:04 pm
Posts: 14293
Location: Fremont, CA, USA
Sorry, I couldn't think of a better word. What I meant was a single type. Start with something simple, then expand the complexity from there. Dimension was probably not the best word to use.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 2:20 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 4:55 pm 
Offline
Forum Contributor

Joined: Sun May 20, 2007 12:13 pm
Posts: 151


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 5:31 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
You know what... matrices multiplication is very useful in Comp. Sci. and has many uses, so I might post here in few days (if I won't forget by then) a class that does that.

Cheers :D


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 12:34 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel
Just to give you some heads up... I've just finished to code the class which will be used to represent a matrix.
I think that now I'll be working on a class which takes a matrix and returns its transposed.

Cheers :D


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 2:15 pm 
Offline
Forum Contributor

Joined: Sun May 20, 2007 12:13 pm
Posts: 151
Ok! I'm back, and I have the code to multiply matrices:
Syntax: [ Download ] [ Hide ]
#note: this starts where my last post left off

for($i=0;$i<sizeof($ma);$i++){#for each row in a

  for($j=0;$i<sizeof($mbT);$j++){#and for each column (not really, but effectively) in b

    $val=0;#initiate the value for the result matrix

    for($c=0;$c<sizeof($mbT[$j]);$c++){#for each row in that column (once again, not really, but effectively)

      $val += $ma[$j][$c] * $mbT[$j][$c];#multiply a's val by b's val and add to $val

    }

    $mR[$i][$j]=$val;#set the value in the result

  }

}


I believe that will work, but i don't have enough time to test it right now.
Oren, let me know when you are done w/ the class, it will be useful to have.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 2:36 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 27, 2007 11:23 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 9:10 pm 
Offline
Forum Contributor

Joined: Sun May 20, 2007 12:13 pm
Posts: 151
Maybe implementing some kind of static method to return an identity matrix.
Some functions for reduced row echelon forms, determinants, etc would be useful


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 2:49 am 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 10, 2007 12:01 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Apr 07, 2006 5:13 am
Posts: 1640
Location: Israel


Top
 Profile  
 
PostPosted: Wed Apr 25, 2018 1:20 pm 
Offline
Forum Newbie

Joined: Wed Apr 25, 2018 12:55 pm
Posts: 2
index.PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="GET" action="mat.php">
MATRIX MULTIPLICATION </br>
Enter rows & columns of M1:
<input type="text" name="m1" />
<input type="text" name="n1"/></br>
Enter rows & columns of M2:
<input type="text" name="m2" />
<input type="text" name="n2"/></br>



<input type="submit" name="sub" value="get elements" />
</form>
</body>
</html>

mat.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$m1=$_GET['m1'];
$n1=$_GET['n1'];
$m2=$_GET['m2'];
$n2=$_GET['n2'];
echo "Enter elements of matrix1:"."</br>";
for($i=1;$i<=$m1;$i++)
{
for($j=1;$j<=$n1;$j++)
{
?>
<form method="get" action="print.php">
<input type="text" name="text1<?php echo $i.$j; ?>" />
<?php
}
echo "</br>";
}
echo "Enter elements of matrix2:"."</br>";
for($i=1;$i<=$m2;$i++)
{
for($j=1;$j<=$n2;$j++)
{
?>
<form method="get" action="print.php">
<input type="text" name="text2<?php echo $i.$j; ?>" />
<?php
}
echo "</br>";
}
?>
<input type="hidden" name="m1" value="<?php echo $m1; ?>" />
<input type="hidden" name="n1" value="<?php echo $n1; ?>" />
<input type="hidden" name="m2" value="<?php echo $m2; ?>" />
<input type="hidden" name="n2" value="<?php echo $n2; ?>" />
<input type="submit" value="click" />
</form>
</body>
</html>

print.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
$m1=$_GET['m1'];
$n1=$_GET['n1'];
$m2=$_GET['m2'];
$n2=$_GET['n2'];
if($n2==$n1)
{
for($i=1;$i<=$m1;$i++)
{
for($j=1;$j<=$n1;$j++)
{
$a[$i][$j]=$_GET['text1'.$i.$j];
}
}
for($i=1;$i<=$m2;$i++)
{
for($j=1;$j<=$n2;$j++)
{
$b[$i][$j]=$_GET['text2'.$i.$j];
}
}
for($i=1;$i<=$m1;$i++)
{
for($j=1;$j<=$n2;$j++)
{
$c[$i][$j]=0;
for($k=1;$k<=$n1;$k++)
$c[$i][$j]=$c[$i][$j]+ $a[$i][$k]*$b[$k][$j];
}
}
for($i=1;$i<=$m1;$i++)
{
for($j=1;$j<=$n2;$j++)
{
echo $c[$i][$j]. " "." "." ";
}
echo "</br>";
}
}
else
{
echo "multiplication not possible";
}
?>
<body>
</body>
</html>

OUTPUT:

[img]C:\Users\HP\Pictures\Saved%20Pictures\Capture2.png[/img]
[img]C:\Users\HP\Pictures\Saved%20Pictures\Capture3.png[/img]
[img]C:\Users\HP\Pictures\Saved%20Pictures\Capture4.png[/img]


Top
 Profile  
 
PostPosted: Wed Apr 25, 2018 1:30 pm 
Offline
Forum Newbie

Joined: Wed Apr 25, 2018 12:55 pm
Posts: 2
output

MATRIX MULTIPLICATION
Enter rows & columns of M1: 3 3
Enter rows & columns of M2: 3 3
Get Elements

Enter elements of matrix1:
1 2 3
4 5 6
7 8 9

Enter elements of matrix2:
1 0 0
0 1 0
0 0 1

result:
1 2 3
4 5 6
7 8 9


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 47 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