What are all the possible combinations given the restrictions?

2 vues (au cours des 30 derniers jours)
Martin Ramirez
Martin Ramirez le 28 Oct 2020
Commenté : Martin Ramirez le 28 Oct 2020
Can someone help me solve this problem?
There are three items sold at a market by a farmer nearby, apples, bananas and strawberries. A bag of apples cost 2 dollars(A=2), bananas cost 3 dollars(B=3) and strawberries cost 4 dollars(S=4). If the items are bought in the month of January the price of the items increase(A=2.50, B=3.75, and S=4.50). If the items are bought any other month (Feb-Dec) the price remains the same(A=2,B=3,S=4). You have 7 dollars and only want to buy 2 different items a year, where only One item has to be bought by a buyer in the month of January and the other item can be bought any other month. Create a code that creates a vector that finds all the possible combinations of buying two items. Keep in mind the items cannot be the same, you have a 7 dollar budget, you can only buy two items and you have to buy one item in January.
Example: if you buy Apples in January (A=2.50) and Strawberries in February(S=4) the total cost is 6.50 which is in your 7 dollar budget. Therefore one combination would be X=[A S]
What are all the other possible combinations given the restrictions?

Réponse acceptée

James Tursa
James Tursa le 28 Oct 2020
Buy any item in January and any other item in the other month. All combinations are valid and within the $8 budget so essentially there are no restrictions on combinations other than you can't buy two of the same item. Write your code accordingly.
  6 commentaires
Steven Lord
Steven Lord le 28 Oct 2020
Forget MATLAB for a moment. If I were to ask you to solve this problem using pencil and paper (or marker and whiteboard, or stick and sandbox, etc.) what steps would you follow to solve it? Be methodical in describing your process.
Now, once you have that process worked out, put each step as a comment line in your file. Then think how you would get MATLAB to perform each step in your process. Any time you'd do something repeatedly, that may be one of the looping constructs in MATLAB (for or while). Decisions or comparisons could be if, ==, <=, etc. If you're not sure how to perform a step in MATLAB, try breaking it into substeps (that are recorded as a comment in your file.)
Martin Ramirez
Martin Ramirez le 28 Oct 2020
Thank you, I'll give it a try

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by