Concept Flow - Matrix arithmetic
Create Matrix A
Create Matrix B
Choose Operation
Add
Result Matrix
Start by creating two matrices, then pick an arithmetic operation (add, subtract, multiply) to get the result matrix.
A <- matrix(c(1,2,3,4), nrow=2) B <- matrix(c(5,6,7,8), nrow=2) C <- A + B C
| Step | Action | Matrix A | Matrix B | Operation | Result C |
|---|---|---|---|---|---|
| 1 | Create A | [1 3; 2 4] | - | - | - |
| 2 | Create B | - | [5 7; 6 8] | - | - |
| 3 | Add A + B | [1 3; 2 4] | [5 7; 6 8] | Addition | [6 10; 8 12] |
| 4 | Output C | - | - | - | [6 10; 8 12] |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| A | NULL | [1 3; 2 4] | [1 3; 2 4] | [1 3; 2 4] | [1 3; 2 4] |
| B | NULL | NULL | [5 7; 6 8] | [5 7; 6 8] | [5 7; 6 8] |
| C | NULL | NULL | NULL | [6 10; 8 12] | [6 10; 8 12] |
Matrix arithmetic in R: - Create matrices with matrix(c(...), nrow=...) - Addition/Subtraction: element-wise, matrices must be same size - Multiplication: use %*% for matrix multiplication - Result is a new matrix - Dimensions must match rules for each operation