Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,788 answers

573 users

How to multiply matrix by vector in PHP

1 Answer

0 votes
function matrix_x_vector($matrix, $vector, &$multiplied_array) {
    $rows = count($matrix);  
    $cols = count($matrix[0]);  
    for ($i = 0; $i < $rows; $i++) {
        for ($j = 0; $j < $cols; $j++) {
            $multiplied_array[$i] += $matrix[$i][$j] * $vector[$j];
        }
    }
}
 
 
$vector = array(3, 4, 3);
$matrix = array(     
            array(0, 3, 5),  
            array(5, 7, 2)
          );  
$multiplied_array = array(0, 0);    
 
matrix_x_vector($matrix, $vector, $multiplied_array);
 
foreach($multiplied_array as $n) {    
    echo $n . " ";
} 
 



/*
run:

27 49  

*/

 





answered Mar 24, 2022 by avibootz

Related questions

1 answer 53 views
1 answer 76 views
76 views asked Mar 27, 2022 by avibootz
2 answers 60 views
60 views asked Mar 23, 2022 by avibootz
1 answer 45 views
45 views asked Mar 23, 2022 by avibootz
1 answer 66 views
...