Create indexed inequalities and variables to represent the calories consumed in a diet. Each meal has a different calorie limit. Create arrays representing the meals, foods, and calories for each food.
Create optimization variables representing the foods for each meal, indexed by food names and meal names.
Set the inequality constraints that each meal has an upper bound on the calories in the meal.
View the inequalities for dinner
.
200*diet('cereal', 'dinner') + 175*diet('oatmeal', 'dinner')
+ 150*diet('yogurt', 'dinner')
+ 450*diet('peanut butter sandwich', 'dinner') + 350*diet('pizza', 'dinner')
+ 800*diet('hamburger', 'dinner') + 150*diet('salad', 'dinner')
+ 650*diet('steak', 'dinner') + 350*diet('casserole', 'dinner')
+ 300*diet('ice cream', 'dinner') <= 750
Instead of using a loop, you can create the same inequalities by using matrix operations on the variables.
Include the appropriate index names for the inequalities by setting the IndexNames
property.
Display the new inequalities for dinner
. Note that they are the same as the previous inequalities.
200*diet('cereal', 'dinner') + 175*diet('oatmeal', 'dinner')
+ 150*diet('yogurt', 'dinner')
+ 450*diet('peanut butter sandwich', 'dinner') + 350*diet('pizza', 'dinner')
+ 800*diet('hamburger', 'dinner') + 150*diet('salad', 'dinner')
+ 650*diet('steak', 'dinner') + 350*diet('casserole', 'dinner')
+ 300*diet('ice cream', 'dinner') <= 750
Creating inequalities in a loop can be more time consuming than creating inequalities by using matrix operations.