I am trying to make an algorithm within Matlab. I have 4 constraints that I need to hit: any suggestions are appreciated.

1 回表示 (過去 30 日間)
Jram
Jram 2019 年 3 月 19 日
コメント済み: Jram 2019 年 3 月 19 日
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?
Screenshot 2019-03-19 at 12.41.59.png

回答 (1 件)

Steven Lord
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.
  1 件のコメント
Jram
Jram 2019 年 3 月 19 日
Thanks Steven, the numbers I added were arbitrary, just to make the point, not real values. Ideally there would be way more food entries to use multipliers for and target requirements could have a +- 10% on them.
Is there a way to loop through multipliers until all constraints are met in matlab? Do you have any suggestions?
Thanks a lot
G

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by