John wants to buy something for himself with his pocket money. He has a budget of $105 to spend on $25 T-shirts, $10 CDs, and $5 books. He wants to buy 10 items and wants to buy as many books as T-shirts and CDs combined. Using MATLAB, how many of each item should he buy? Write a system of equations to help you solve this problem.
Please include everything that must be typed in to accomplish this
Given that,
system of equations:
let,
x = number of T-Shirts bought,
y = number of CDs bought,
z = number of books bought
Given that,
total money spent = $105, so , the first equation is :
25x + 10y + 5z = 105
Then, total number of items bought is 10, the second equation is:
x + y + z = 10
Then. number of books(z) = number of CDs and T-Shirts combined(x+y). The equation is:
x + y - z = 0
Now, we have the system of linear equation, we will solve it using the backslash \ operator
program:
%System of equations:
%25x + 10y + 5z = 105 : A total of $105 spent
%x + y + z = 10 : A total of 10 items bought
%x + y - z = 0 : number of t-shirts + CDs = number of books
A = [25 10 5; 1 1 1; 1 1 -1];
b = [105; 10; 0];
X = A\b;
fprintf('Number of T-shirts: %d\n', X(1))
fprintf('Number of CDs: %d\n',X(2))
fprintf('Number of books: %d\n',X(3))
output:
Number of T-shirts: 2.000000e+00
Number of CDs: 3.000000e+00
Number of books: 5
Get Answers For Free
Most questions answered within 1 hours.