1. ## Matrices

Hi,

I'm working on multiplying matrices for homework and I'm stuck for a long time. This is my assignment:

{x}(n+1) = [K] {x}(n), n = 0,1,2, ... ,8,9.

In other words, the next vector {x} is equal to the product of [K] and
the current vector {x}.

I have the basic program already but I couldn't get it to multiply the current matrix. Instead, it would only multiply the initial matrix.

Part I'm stuck on:

Code:
```for(n=1; n<=10; n++)
{
printf("\nNew Vector:\n");
printf("y[%d] : [", n);
matrix_mult(K, x, y, 4);
printf(" ]\n");

}```
K and x are the matrices I have to multiply together (they're already defined), y is the resulting matrix. I don't know how to make it so that the program will take K*y next instead of K*x(0). Please help?

2. So, basically, you need to assign y to x for the next iteration of your loop?

Well, doing that depends on what type x and y are (assuming they're the same type, of course). If they're arrays, you can use memcpy() like so:
Code:
```int newarray[3][3], array[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
memcpy(newarray, array, sizeof(array));```

3. Thanks for helping.

Yes! I need to assign y to x for the next loop. And yes, they're arrays. But is there another way to do it? I haven't seen memcpy() before so I don't know if that's allowed on the homework.

4. Well, you could always just use a for loop, or a nested for loop for a two dimensional array, which is what I'm assuming your array is:
Code:
```int newarray[3][3], array[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
int x, y;

for(x = 0; x < 3; x ++) {
for(y = 0; y < 3; y ++) newarray[x][y] = array[x][y];
}```
or even
Code:
```int newarray[3][3], array[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
int x, y;

for(x = 0; x < sizeof(array)/sizeof(*array); x ++) {
for(y = 0; y < sizeof(*array)/sizeof(**array); y ++) newarray[x][y] = array[x][y];
}```
But wait, let me guess. You haven't covered sizeof() . . .

5. I've seen sizeof() already but sorry I forgot to tell you that x and y are both one dimensional array. I tried to modify what you gave me, however, it's not working. I'm still getting the same answer before--K*x(0) instead.

6. Well, for one dimensional arrays, it's quite simple.
Code:
```int newarray[9], array[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int x;

for(x = 0; x < sizeof(array)/sizeof(*array); x ++) {
newarray[x] = array[x];
}```