Re: scanning one matrix over another matrix
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 03/08/04
- Next message: Julie: "Re: How did C++ beat the competition?"
- Previous message: E. Robert Tisdale: "Troll Alert: Fortran from C++"
- In reply to: seia0106: "scanning one matrix over another matrix"
- Next in thread: seia0106: "Re: scanning one matrix over another matrix"
- Reply: seia0106: "Re: scanning one matrix over another matrix"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 8 Mar 2004 18:57:51 -0000
"seia0106" <miahmed67@yahoo.com> wrote in message
news:4fe296bd.0403081022.3ea3f6f2@posting.google.com...
> Hello everyone,
> I am trying to write a function using For loops that should make one
> matrix slide over another bigger matrix and calculate scalar product
> in each step. For example here are the two matrices
> int
A[5][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,2
3,24,25}};
> int B[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
>
> What i want is to put matrix B on top of Matrix A(starting top left),
> calculate scalar product of B and that portion(3x3) of A that lies
> under B, then move one column right , again calculate scalar product
> and repeat this process till last column and then do the same with
> row 2.
> What i am fiding difficult is how to write the For loops for this kind
> of operation.
> Can anyone please kindly provide some help in solving this problem. It
> may sound easy to many of you but is causing difficulty to me.
> Thanks in advance.
How about this
for (int startRow = 0; startRow <= 2; ++startRow)
{
for (int startCol = 0; startCol <= 2; ++startCol)
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
int a = A[startRow + i][startCol + j];
int b = B[i][j];
// calculate scalar product somehow from a and b
}
}
}
}
john
- Next message: Julie: "Re: How did C++ beat the competition?"
- Previous message: E. Robert Tisdale: "Troll Alert: Fortran from C++"
- In reply to: seia0106: "scanning one matrix over another matrix"
- Next in thread: seia0106: "Re: scanning one matrix over another matrix"
- Reply: seia0106: "Re: scanning one matrix over another matrix"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|