Practical - 4 IWD
AIM : Write a script to perform 3x3 matrix Multiplication.
3×3 Matrix Multiplication using PHP
📌 Theory (For Exam)
-
Matrix multiplication is possible only if
Number of columns of Matrix A = Number of rows of Matrix B -
For 3×3 matrices, the result is also a 3×3 matrix
-
Formula used:
✅ PHP Script for 3×3 Matrix Multiplication
🧠Step-by-Step Explanation
1️⃣ Matrix Declaration
-
Two 3×3 matrices are defined using 2D arrays
2️⃣ Result Matrix Initialization
-
Stores the final multiplication result
3️⃣ Matrix Multiplication Logic
-
Outer loop (
$i) → Row of Matrix A -
Middle loop (
$j) → Column of Matrix B -
Inner loop (
$k) → Performs multiplication and addition
📊 Sample Output
🎓 Viva / Exam Questions
Q1. Why three loops are used?
👉 To traverse rows, columns, and perform multiplication.
Q2. Condition for matrix multiplication?
👉 Columns of first matrix = Rows of second matrix.
Q3. Data structure used?
👉 Two-dimensional array.
Q4. Size of resultant matrix?
👉 Same as rows of first matrix × columns of second matrix.
Comments
Post a Comment