well i have a problem with logic of matrices multiplication in php; the data comes from the database in the form of an one dimension array (Array ( [0] => 1.0000 [1] => 0.5000 [2] => 3.0000 [3] => 2.0000 [4] => 1.0000 [5] => 5.0000 [6] => 0.3333 [7] => 0.2000 [8] => 1.0000 )
), that I need to transform into a matrice. The dimension of the original array is a square number (in this case 9), so the result matrice will have two equal dimensions, both equal to the square root (3) of the original data array.
The result matrice has to be multiplied by itself, using the pattern in the image below:
I have made some research before, but none of them were right.
i have the following code i used in the model to create the algorithm:
function hitung_matriks(){
$query = $this->db->query("select * from banding b
inner join kriteria a on a.Kd_Kriteria1 = b.Kd_Kriteria1");
$dt_matriks = $query->result();
$data = array();
foreach($dt_matriks as $a){
$data[] = $a->Nilai_Banding;
}
echo "<pre>";
print_r($data);
echo "</pre>";
$c = array();
for($i=1;$i<=sqrt(count($data));$i++){
$d = array();
$isi=0;
for($j=1;$j<=sqrt(count($data));$j++){
$isi = $data[$i][$j] * $data[$j][$i];
$d[] = $isi;
}
$c[] = $d;
}
echo "<pre>";
print_r($c);
echo "</pre>";die();
}
and the result of each array comes 0.
I want to make this code works to be like this :
please help me :'(