Creating a matrix from a list of equations

Hello,

I was wondering if its possible to create a c++ program where a set of 3 variables each have a value. A list of items each contain a different value for each of those 3 variables. The program then selects 3 random items and creates 3x3 matrix and solves it to produce how many of each item are needed.

An example using math terms would be:

X= 22 , Y= 38 ,Z= 29

Item 1: X= 2 Y= 4 Z= 5
Item 2: X= 3 Y= 3 Z= 1
Item 3: X= 1 Y= 1 Z= 1
Item 4: X= 2 Y= 3 Z= 4
Item 5: X= 2 Y= 5 Z= 3

Program picks 3 random items, creates a matrix, solves it, and then outputs:
"You need 3(Item 1) 2(item 2) and 4(item 5)to meet the requirements X=22 Y=38 and Z= 29"

The program could then be ran again but would pick another set of 3 items that also meets the requirements of X Y and Z.

If this can be done and anyone knows how or knows any information I could read to learn how to do this it would be a great help.
Last edited on
Divide your problem into parts, solve them and finally code them:

Problem 1: Get input. It might be hardcoded, user-provided or read from file. Also you want to choose a container to store data. It is obvious that yo want to store each individual item in structure (tuple?) and all items should be in another (dynamic? vector?) container.

Problem 2: Choose three items at random. Knowing size of container and having access to either C random facilities (Bad) or C++ random number generators (good) it is easy. Potential problem: how to handle picking same item twice? Potential solutions: remove items as they are selected, randomly shuffle array and choos first three elements.

Problem 3: Solve system of equations. How would you do it by hand? How to represent that system? How to code solution?


If you have trouble with any part, try to divide it further. If you cannot, tell what exactly you have problem with, and we will help.
closed account (48T7M4Gy)
Sounds like linear anaysis/programming/optimisation. If so the answer is yes and matrices would eat it. There are many good sources if you surf around for code to handle matrices, especially small 3x3 matrices which you could write yourself with reasonable C++ skill.

Wikipedia is a good start to get a handle on the technology, especially to see whether it fits.
Thanks for inputs, I'll use what you guys have said and research how to build my code. If I get stuck ill open another thread with the exact problem.
Topic archived. No new replies allowed.