Hướng dẫn write a php program to do the multiplication of two matrices - viết một chương trình php để thực hiện phép nhân hai ma trận

Cho hai ma trận, nhiệm vụ để nhân chúng. Ma trận có thể là hình vuông hoặc hình chữ nhật.

Examples:  

Input : mat1[][] = {{1, 2}, 
                   {3, 4}}
        mat2[][] = {{1, 1}, 
                    {1, 1}}
Output : {{3, 3}, 
          {7, 7}}
Input : mat1[][] = {{2, 4}, 
                    {3, 4}}
        mat2[][] = {{1, 2}, 
                    {1, 3}}       
Output : {{6, 16}, 
          {7, 18}}

Hướng dẫn write a php program to do the multiplication of two matrices - viết một chương trình php để thực hiện phép nhân hai ma trận

Phép nhân của ma trận vuông: & nbsp; chương trình bên dưới nhân hai ma trận vuông có kích thước 4*4, chúng ta có thể thay đổi n cho các kích thước khác nhau. & Nbsp;
The below program multiplies two square matrices of size 4*4, we can change N for different dimensions. 

PHP

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
4

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9function1

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

multiply(&1$resmultiply(&3

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8multiply(&5function1multiply(&7

multiply(&1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7$mat11
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9$mat11 1__

$mat19$resmultiply(&3

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8multiply(&5function1, &5$mat1multiply(&3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8multiply(&5$mat11$mat21

$mat22$mat2multiply(&3$mat11multiply(&5function1$mat28

8, &0

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2, &0

, &0

$mat1 , &5, &6

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7, &6, &9

$res0, &6$res2

$res0, &6$res5

$res0, &6$res8

$mat2 , &5, &6

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7, &6__

$res0, &6$res2

$res0, &6$res5

$res0, &6$res8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
14$mat1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16$mat2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16$res
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
20

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
4

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
23
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
24

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
25

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8 1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3__

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9function1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
23
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7$resmultiply(&3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8multiply(&5function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
58

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
23
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
62
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
20

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2, &0

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
23
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
68

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
25

, &0

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
71

Đầu ra

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40

Độ phức tạp về thời gian: O (N3). Nó có thể được tối ưu hóa bằng cách nhân ma trận Strassen O(n3). It can be optimized using Strassen’s Matrix Multiplication

Không gian phụ trợ: O (N2) O(n2)

Sự nhân của ma trận hình chữ nhật: & nbsp; chúng tôi sử dụng con trỏ trong C để nhân với ma trận. Vui lòng tham khảo bài đăng sau dưới dạng điều kiện tiên quyết của mã. Làm thế nào để chuyển một mảng 2D dưới dạng tham số trong C? & NBSP;
We use pointers in C to multiply to matrices. Please refer to the following post as a prerequisite of the code.
How to pass a 2D array as a parameter in C? 

PHP

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
81
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
82
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
84
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16$mat2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
87

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
4

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
88

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9function1

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
88

multiply(&1$resmultiply(&3

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8multiply(&5function121

multiply(&1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7$mat11
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9$mat11 1__

multiply(&1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
88

$mat1 , &5, &6

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7, &6, &9

$mat22$mat2multiply(&325multiply(&5function154

multiply(&156

856

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
256

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
88

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9function1

8

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
88

multiply(&1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7$mat11
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9$mat11 1__

856

$mat1 , &5, &6

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7, &6, &9

function02

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
256

56

$mat2 , &5, &6

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7, &6__

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
4

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
23
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
24

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
8 1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
3__

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
6
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
7function1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
9function1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
2
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
1

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
14
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
75
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
77
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16$mat1
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
82
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
84
Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
16$mat2function42

Result matrix is 
10 10 10 10 
20 20 20 20 
30 30 30 30 
40 40 40 40
71

Độ phức tạp về thời gian: O (N3). Nó có thể được tối ưu hóa bằng cách nhân ma trận Strassen O(n3). It can be optimized using Strassen’s Matrix Multiplication

Không gian phụ trợ: O (N2)O(m1 * n2)

Sự nhân của ma trận hình chữ nhật: & nbsp; chúng tôi sử dụng con trỏ trong C để nhân với ma trận. Vui lòng tham khảo bài đăng sau dưới dạng điều kiện tiên quyết của mã. Làm thế nào để chuyển một mảng 2D dưới dạng tham số trong C? & NBSP;


Làm thế nào để bạn viết một chương trình nhân ma trận?

Thuật toán của phép nhân ma trận lập trình C..
Start..
Nhập giá trị của thứ tự m và n (hoặc) của ma trận đầu tiên ..
Nhập giá trị của thứ tự p và q (hoặc) của ma trận thứ hai ..
Tạo một ma trận có kích thước A [M] [N] và B [P] [Q] ..
Nhập phần tử của ma trận hàng theo cách sử dụng các vòng lặp ..

Sản phẩm của 2 ma trận là gì?

Sản phẩm của hai ma trận A và B được xác định nếu số lượng cột của A bằng với số lượng hàng của B. Nếu cả A và B đều là ma trận vuông của cùng một thứ tự, thì cả AB và BA đều được xác định.Nếu AB và BA đều được xác định, không cần thiết AB = BA.if the number of columns of A is equal to the number of rows of B. If both A and B are square matrices of the same order, then both AB and BA are defined. If AB and BA are both defined, it is not necessary that AB = BA.

Nhân php là gì?

Các toán tử số học PHP.