CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Find cartesians for matrix elements

1. Junior Member
Join Date
Jul 2021
Posts
9

## Find cartesians that fills zero-one matrix

Hi All! I am new here.
I am wondering what is the name for the following algorithm I need to code. If I know the name I could find the algorithm.

1st example
Suppose I have a matrix
Code:
``` 123
Aoo
Boo
C oo
D  o
E oo```
Having it as an input I need to create an output like this:
ABx12, CEx23, Dx3 (x means cartesian product)

2nd example
Code:
``` 12345
A oo o
B o  o
Coo
Doo oo
Eo  oo
F  ooo```
should give me an output like
ABx25, CDx12, DEFx45, AFx3, Ex1

Jacek
Last edited by JackK; July 14th, 2021 at 07:34 AM.

2. ## Re: Find cartesians for matrix elements

It is absolutely not clear what you want to get and what your initial matrices are. What are the dimensions of your matrices?

You may also try to find out something useful and similar to your need here:

3. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

Originally Posted by VictorN
It is absolutely not clear what you want to get and what your initial matrices are. What are the dimensions of your matrices?
Hmm... The former matrix's dimension is 3x5, the latter is 5x6.
I thought I wrote it rather clear

4. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

So maybe another example will be more clear.

Matrix is (dimension 3x3)
Code:
```101
111
110```
Output should be
Code:
```000   001   100
110 + 001 + 000
110   000   000```
or
Code:
```101   000   000
101 + 010 + 000
000   010   100```

5. ## Re: Find cartesians for matrix elements

Originally Posted by JackK
Hmm... The former matrix's dimension is 3x5, the latter is 5x6.
I thought I wrote it rather clear
No, you didn't.

6. Junior Member
Join Date
Jul 2021
Posts
9

7. ## Re: Find cartesians for matrix elements

Originally Posted by JackK
So maybe another example will be more clear.

Matrix is (dimension 3x3)
Code:
```101
111
110```
DO you mean
Code:
```1 0 1
1 1 1
1 1 0```
or something else?

Originally Posted by JackK
Output should be
Code:
```000   001   100
110 + 001 + 000
110   000   000```
or
Code:
```101   000   000
101 + 010 + 000
000   010   100```
What is the dimension of "Output"?
What are these "+" (plus) symbols mean?

BTW, did you find something useful and similar to your needs in the pictures I have posted?

8. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

Originally Posted by VictorN
Do you mean
Code:
```1 0 1
1 1 1
1 1 0```
or something else?
I do mean exactly this.

Originally Posted by VictorN
What is the dimension of "Output"?
The same as "Input".

Originally Posted by VictorN
What are these "+" (plus) symbols mean?
"+" means that my "Input" is a sum of "Output" matrixes.

Originally Posted by VictorN
BTW, did you find something useful and similar to your needs in the pictures I have posted?
No, rather not.

9. ## Re: Find cartesians for matrix elements

See https://stackoverflow.com/questions/...n-product-in-c re info about generating cartesian product sets.

Also
https://gist.github.com/Alexhuszagh/...529ed97586646a

Doing an Internet search https://uk.search.yahoo.com/search?f...duct%20c%2B%2B provides many links to info re implementing cartesian products in C++

10. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

Maybe I put my requirement in a wrong way.

My requirement is to find submatrixes (minimum amount of them) which sum to my input matrix. Each submatrix must be possible to represent as a one and only one cartesian product. Input matrix is matrix of only 0 and 1 elements.

For example:
input
Code:
```  a b c d
A 0 1 1 1
B 0 1 1 1
C 0 1 1 0
D 1 1 0 0```
output (x means cartesian product)
1. (A,B)x(b,c,d) + (C)x(b,c) + (D)x(a,b)
what is equal to
Code:
```  a b c d   a b c d   a b c d
A 0 1 1 1   0 0 0 0   0 0 0 0
B 0 1 1 1   0 0 0 0   0 0 0 0
C 0 0 0 0 + 0 1 1 0 + 0 0 0 0
D 0 0 0 0   0 0 0 0   1 1 0 0```
or
2. (A,B,C)x(b,c) + (A,B)x(d) + (D)x(a,b)
what is equal to
Code:
```  a b c d   a b c d   a b c d
A 0 1 1 0   0 0 0 1   0 0 0 0
B 0 1 1 0   0 0 0 1   0 0 0 0
C 0 1 1 0 + 0 0 0 0 + 0 0 0 0
D 0 0 0 0   0 0 0 0   1 1 0 0```
(so my input matrix can be split into 3 submatrices)
Last edited by JackK; July 14th, 2021 at 07:45 AM.

11. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

Is there still not all clear in my requirement?
Should I explain it more (if possible)?

12. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

No more help?

13. ## Re: Find cartesians for matrix elements

As this is not a C++ question, but an algorithm question - the only help I can provide is to suggest that first you solve this using pen/paper to develop the algorithm. Once you produce what you require that way, then you can produce a program design and code from the design.

Sorry, but I can't help you with the required algorithm. But once you have the design, I'll probably be able to provide guidance with the C++ coding.

14. Junior Member
Join Date
Jul 2021
Posts
9

## Re: Find cartesians for matrix elements

But the problem is that the algorithm is unknown to me yet.
I thought that it's maybe known to some of you.

15. ## Re: Find cartesians for matrix elements

Presumably not.......

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•