perkalian matrix :

//array : 1 var yg memiliki anggota lebih dari 1
$kota=array(“Jakarta”, “Denpasar”, “Bandung”, “Bekasi”);// 1 dimensi
$matrix_A=    array(    array(2,4),
array(3,1)); // multi dimensi

$matrix_B=    array(    array(1,5),
array(2,4)); // multi dimensi
// echo “Matrix A :<br/>”;
// echo $matrix_C[0][0]=$matrix_A[0][0]+$matrix_B[0][0].”  “;
// echo $matrix_A[0][1].”<br/>”;
// echo $matrix_A[1][0].”  “;
// echo $matrix_A[1][1].”<br/>”;

$anggota_row=count($matrix_A);
$anggota_kol=count($matrix_A[0]);
for ($i=0; $i < $anggota_row; $i++)
{
for ($j=0; $j < $anggota_kol; $j++)
{
echo $matrix_C[$i][$j]=$matrix_A[$i][$j]+$matrix_B[$i][$j].”  “;
}
echo “<br/>”;
}

echo “perkalian matrix : <br>”;

for ($i=0; $i < $anggota_row; $i++)
{
for ($j=0; $j < $anggota_kol; $j++)
{
$hasil=0;
for ($k=0; $k < $anggota_kol; $k++)
{
$hasil=$hasil+($matrix_A[$i][$k]*$matrix_B[$k][$j]);

}
$matrix_C[$i][$j]=$hasil;
echo $matrix_C[$i][$j].”  “;
}
echo “<br/>”;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s