How Can Miss_Lolitta Program an Integer Matrix with Symmetrical Constraints?

  • Thread starter Thread starter Miss_lolitta
  • Start date Start date
AI Thread Summary
The discussion centers around creating a program to generate an NxN integer matrix with specific constraints. The matrix must have entries ranging from 0 to 2, with the first row mirroring the first column, all diagonal entries set to zero, and the sum of each row and column equaling 4. The initial steps involve gathering user input for N, constructing the matrix, and filling the diagonal with zeros. A significant focus is placed on developing an algorithm to satisfy the matrix's rules, emphasizing the importance of logical design before coding. The conversation suggests using mathematical reasoning to solve the constraints, leading to a unique solution for a 3x3 matrix, which exemplifies the relationship between mathematics and computer science in programming. The overall aim is to assist in understanding how to approach the problem systematically before implementing it in a programming language like C++.
Miss_lolitta
Messages
10
Reaction score
0
Hi,,
I am hoping that you will help me. I have trouble how can do this homework:
Write a program that allows the user to input a number of integers such as N, and then stores them in an integer matrix where:

1- The dimension of matrix = NXN.
2-Entries of matrix can take any number from 0-2.
3- Arrangement of entries of first row is the same arrangement of entries of first column.
4-The diagonal of matrix =o.
5- Total of every row =4,Also Total of every column.

Then, the program displays the result.

Your help would greatly be appreciated

Respectfully,,
Miss_Lolitta
 

Attachments

Computer science news on Phys.org
Is there a particular language that the program is to be written in?
 
hey perhaps we can sit your exams for you too?

At least try and do it, and post what progress you have gotten through!
 
Isn't this in the wrong section? Shouldn't it be in the homework section?
 
I would like to write this program in C++.I learn the programming language at an institute,and I am not expert in this branch but I try to become better with your first help.

I would be so ever grateful if you could help me on how to go about writing this program.

thanks,,
 
OK, forget about the programming language, forget about the computer. Pick up a pencil.

Design you logic first. Start at a high level, then break it down.
1] Gets integer from user: N.
2] Creates a matrix: NxN.
3] Fills in the diagonal values with zeros.
4] ?? - You must decide on your algorthim for checking against your rules.

Clearly step 4 is the bulk of the program. How do you propose to check?
Brute force?
000 000 000 = No.
000 000 001 = No
000 000 002 = No
000 000 010 = No
etc.
Is there a better way to do this? Knowing the rules you have to stay within, and the possible values (0-2), are there any steps you can eliminate? (Note that of the above tests, only 2 of them are valid, considering the "diagonal rule". You don't even need to test them.)

Hint: you're going to be needing a lot of loops and a lot of 'if's.

There is no point in going anywhere near a programming language or a computer until you've worked out your logic.
 
Last edited:
Really, forget about the programming language, forget about the computer. Look at this method to solve this problem in maths:

1] Gets integer from user: N. such as N=3

2] Creates a matrix: 3x3

X Y Z
X Y Z
X Y Z

3] Fills in the diagonal values with zeros.

0 Y Z
X 0 Z
X Y 0

>>> then we have the following system:

0 Y Z = 4
X 0 Z = 4
X Y 0 = 4

>>> by solving this system we have a unique solution:X=2,Y=2,Z=2

>>> So, we have matrix

0 2 2
2 0 2
2 2 0


Hint: we have a symmetry between diagonals of matrix

I know that there is relation between maths and CS to solve mathematical problems..because of this I would like to study the programming languages.

Any help you give I'd be very glad . Thank you for your assistance.
 
Back
Top