Question

Many ATMs (automatic teller machines) dispense only $20 bills. For example, withdrawing $120 woul...

  • Many ATMs (automatic teller machines) dispense only $20 bills. For example, withdrawing $120 would yield 6 $20 bills. US currency includes a nice assortment of values. It would be much more interesting* to go into the bank and ask for six bills that add up to $120 and receive one $100, one $10, one $5, two $2, and one $1. Write a MATLAB function which, given a total dollar amount and a number of bills, calculates all the possible combinations of exactly that number of bills that add up to that total dollar amount. The function definition and a few examples are shown below (note: the order of the rows in the result is not important). Test your function using the given examples. The third example has many answers; for this example print out only the answer which has the highest number of unusual bills, with "unusual" being interpreted as $50 and $2 bills (finding this answer may be done by hand - you don't need to write a program to find it from among all the answers, however, if you think about it for a while you should be able to write a single-line MATLAB command which will do it for you). Hint: loops will be useful; one or more of the functions ceil, fix, floor, or round might be useful. (* for some definition of "interesting")
    Function header:
    function [ result ] = currency_combinations ( target , n )
    % [ result ] = currency_combinations ( target , n )
    %
    % Find all combinations of n bills that add up to the target amount (assuming US currency is used).
    %
    % Input arguments: target is dollar amount, n is number of bills.
    % Output arguments: the result is a matrix in which each row is one solution.
    % The values in an output row are, in order, the numbers of $100, $50, $20, $10, $5, $2, and $1 bills.
    %
    % If there is no solution an empty result is returned.
    % If the input parameters are invalid a warning is printed and an empty result is returned.
    
    Examples:
    >> E1 = currency_combinations(140,7)
    E1 =
    
       0   0   7   0   0   0   0
       0   1   3   3   0   0   0
       0   1   4   0   2   0   0
       0   2   0   3   2   0   0
       0   2   1   0   4   0   0
       1   0   0   2   4   0   0
       1   0   1   1   1   2   1
    
    >> E2 = currency_combinations(60,1)
    E2 = [ ]
    
    >> E3 = currency_combinations(500,25)
    ...answer not shown...

NEED MATLAB CODE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Write the MATLAB function that calculations all possible combinations to get the target amount. The inputs to the function ar

comb inations (500,25) currency >> ans= 1 3 0 0 0 0 2 2 5 0 1 0 C C 4 C C 1 C 2 4

Add a comment
Know the answer?
Add Answer to:
Many ATMs (automatic teller machines) dispense only $20 bills. For example, withdrawing $120 woul...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT