Matrix transposition

Nov 11, 2020 at 12:02pm
Hello, I need to make a code for two transposition matrices, and then they are counted according to the task in the picture. How can I do that? I just don't understand at all

Matrix A
|1|
|2|
|4|

Matrix B
|0|
|3|
|2|

Task
C=2A*B

transposition over the letter A or multiplication * (T)
Nov 11, 2020 at 12:10pm
Is the problem that you don't understand the maths - i.e. that you don't know what to do to get the result?

Or is it that you don't understand how to write the code that implements the maths that you do understand?
Nov 11, 2020 at 12:22pm
I don't understand the matrix math and how the code can be done with transposition matrices and task like this
Nov 11, 2020 at 1:27pm
@Obeliks2,
Your written description of the problem makes no sense at all.
transposition over the letter A or multiplication * (T)

What exactly is that supposed to say?

If you can't state the problem correctly then people can't help you.

Perhaps you could provide a picture or link to the original exercise.
Nov 11, 2020 at 1:50pm
Task
C=2A*B


You need to specify what is meant by '*' in the context of array multiplication. In matrix algebra, you can't multiply a 3x1 matrix by a 3x1 matrix.

The usual rule of matrix multiplication of 2 matrices of dimensions r1, c1 and r2, c2 is that r2 = c1 resulting in a matrix of dimensions r1, c2
Last edited on Nov 11, 2020 at 1:50pm
Nov 11, 2020 at 1:59pm
I think I get it. The * means transposition.
So it's saying transpose A, then multiple by with B.

OP, you should practice transposing/multiplying 2x1 and 1x2 matrices first, and see the patterns there, and then see the pattern in 3x1 and 1x3. Show us what what result should be in your example problem.

https://www.mathsisfun.com/algebra/matrix-multiplying.html
Last edited on Nov 11, 2020 at 2:01pm
Nov 11, 2020 at 2:03pm
So using the original matrices,
2A gives

2
4
8

which transposed gives

2 4 8

then multiply by

0
3
2

which gives

28

Or transposing B then gives

2
4
8

multiply 0 3 2 which gives

0 6 4
0 12 8
0 24 16

???
Last edited on Nov 11, 2020 at 2:13pm
Nov 11, 2020 at 2:06pm
Yes (assuming that's what it means). But it's Obeliks that needs to ask that and try it out him/herself.

Edit: You edited your post. I was saying yes to the 28.
Last edited on Nov 11, 2020 at 5:12pm
Nov 11, 2020 at 4:26pm
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <valarray>
using namespace std;

int main()
{
   valarray<double> A{ 1, 2, 4 }, B{ 0, 3, 2 };
   cout << 2 * ( A * B ).sum() << '\n';
}
Nov 11, 2020 at 5:19pm
https://imgur.com/a/YozrsK8
Here is a picture that shows more which matrices are in the task and which task is under them



Also, I found out code, but whether it does transpose matrices I still don't understand. And which code makes the task easier and more correct? This one or which made by lastchance?
1
2
3
4
5
6
7
8
#include <iostream>
 
int main()
{
    int A[] = { 1, 2, 4 };
    int B[] = { 0, 3, 2 };
    std::cout << "C = " << (2 * (A[0] * B[0] + A[1] * B[1] + A[2] * B[2]));
}






Last edited on Nov 11, 2020 at 5:20pm
Nov 11, 2020 at 5:21pm
For anyone that doesn't want to click on the screenshot, it's just saying: 2 ATB

Both your 'found' code and lastchance's do essentially the same thing.
Both are written in such a way that the A array is "pre-transposed" so you are essentially just doing a dot product and then scaling it by 2.
Last edited on Nov 11, 2020 at 5:24pm
Nov 11, 2020 at 5:27pm
Does this mean that these two codes are already fully executed task or not yet?
Nov 11, 2020 at 5:36pm
We have no idea what the requirements of your actual assignment are. The code in question produces the answer to the "problem" in the screenshot you have shown. If that's all you need to do, then you're done.

The code executes the multiplication/addition at run-time (assuming the compiler isn't aggressively optimizing).
Not sure what you're asking.
Last edited on Nov 11, 2020 at 5:39pm
Topic archived. No new replies allowed.