I am trying to make an algorithm within Matlab. I have 4 constraints that I need to hit: any suggestions are appreciated.
1 回表示 (過去 30 日間)
古いコメントを表示
Is there a code that I can develop to the following problem.
Each entry has attributes of calories, protein, fats, carbs.
Is there a way in Matlab to find the multipliers x,y,z,v for portions sizes so that the attributes hit the 4 sum constraints in red?
0 件のコメント
回答 (1 件)
Steven Lord
2019 年 3 月 19 日
No, not without involving negative amounts of some of these foodstuffs.
Consider if you ate just one of these entries exclusively. That would require 2000/30 portions of pasta, 2000/70 of bread, 2000/100 of chicken, or 2000/15 of avocado to reach the 2000 calories you want to achieve. How much fat would you have in each of those scenarios?
portions = 2000./[30 70 100 15];
fat = portions.*[5 6 7 8];
That puts you well over the limit of 15 for your fat intake; the minimum you could do would be 140 for a diet of pure chicken. That would also violate your protein and carb constraints, providing 400 of each.
If you tell us more about the problem (are those constraints equality or inequality constraints, and are they minimum requirements or maximum allowances?) and/or show us the code you've written we may be able to offer other suggestions. But since this sounds like a homework assignment, without seeing code we'll probably just offer pointers to useful functions.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!