I'm making a fridge app which will use the known data (the amount of servings remaining for each food item and the amount in grams of carbs, proteins, fats in each serving of a given food item) in order to suggest a combination of food items that the user has that will be close to the user's desired amounts in grams of carbs, proteins, fats per day.
I have a nonlinear system of equations Ax = b.
The A matrix is 3 rows tall and m columns wide.
The b matrix is 3 rows by 1 column.
The x matrix is m rows by 1 column.
Both A and b are known. The goal is to find a value for x that will make Ax as close to b as possible.
numservings is a matrix where numservings[i] is the number of servings available of the food item with index i.
The constraints are that each coefficient c_i has to be integer and has to have value 0, 1, 2, up to numservings[i]. These constraints are easy to understand but they would make solving the system harder.
I was thinking of using Least Squares to find an approximate solution. This added constraint will make things harder.
- How can I make an algorithm to suggest the user eat this number of servings for food item 1, another number of servings for food item 2, and so on?
- How can I most accurately solve a nonsquare linear system of equations with constraints on coefficients like I described above?
Thanks for reading!