Calculation of 3 eqns at once and calculating the cost of the three items given the total
1 次查看(过去 30 天)
显示 更早的评论
Hi all i am trying to calculate a question regarding the prices of each item if you are given a total.
how would i calculate the prices of items given that:
Ben spent $18.25 on one pizza, five cans of coke and two bars of chocolate.
Jez spent $17.30 while buying two pizzas, one can of coke and three bars of chocolate.
Cath spent $23.50 while buying three pizzas, seven cans of soft drink and one chocolate bar.
i need to calcualte individual price for the three items and formulate the equations
im not sure where to start with this and any help would be greatly appreciated!
thanks in advance.
10 个评论
Walter Roberson
2021-9-12
Cath spent $23.50 while buying three pizzas, seven cans of soft drink and one chocolate bar.
Where is "seven" of something encoded in your A matrix?
A = [1 5 2;6 8 3; 5 4 9]
B = [18.25; 17.30; 23.50]
X = A\B
B_reconstruct = A*X;
compose("%d pizza @ $%.2f each + %d soft drink @ $%.2f each + %d chocolate bar at $%.2f each = $%.2f", A(:,1), X(1), A(:,2), X(2), A(:,3), X(3), B_reconstruct(:))
If your pizza is coming out at a negative price, you have probably done something wrong.
... DId Jez really buy 6 pizzas ??
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!