Multiplying matrix columns

I have a matrix with n rows and 3 columns, and I should multiply row n column 2 with row n column 3. So if I have a matrix that looks like this:

1 2 3

4 5 6

7 8 9

Then I should multiply 2 with 3, 5 with 6 and 8 with 9, and create a matrix or an array that holds results:

6

30

72

How can I do that in C?


Since you are interested in learning C, an outline should do :-) The output is going to be a single column vector. Input to your function is a matrix, of some dimension pxq, and two column numbers c1 and c2. You can not skin it at least two ways.

  • a function that does exactly what your problem asks, iterating x[1..p][c1] and x[1..p][c2] (so loop variable will be row numbers 1..p, and multiply them, producing result[1..p]

  • a function that returns a column vector from a given matrix, and then another function that does the element-wise product of two vectors as above. This jimho might be a more interesting option.

  • HTH

    链接地址: http://www.djcxy.com/p/85986.html

    上一篇: 在C中将较大的矩阵乘以一个小矩阵

    下一篇: 乘以矩阵列