フィルターのクリア

Calculation of 3 eqns at once and calculating the cost of the three items given the total

1 回表示 (過去 30 日間)
Joe Ainsworth
Joe Ainsworth 2021 年 9 月 12 日
コメント済み: Joe Ainsworth 2021 年 9 月 13 日
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
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]
A = 3×3
1 5 2 6 8 3 5 4 9
B = [18.25; 17.30; 23.50]
B = 3×1
18.2500 17.3000 23.5000
X = A\B
X = 3×1
-2.5832 3.0991 2.6689
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(:))
ans = 3×1 string array
"1 pizza @ $-2.58 each + 5 soft drink @ $3.10 each + 2 chocolate bar at $2.67 each = $18.25" "6 pizza @ $-2.58 each + 8 soft drink @ $3.10 each + 3 chocolate bar at $2.67 each = $17.30" "5 pizza @ $-2.58 each + 4 soft drink @ $3.10 each + 9 chocolate bar at $2.67 each = $23.50"
If your pizza is coming out at a negative price, you have probably done something wrong.
... DId Jez really buy 6 pizzas ??
Joe Ainsworth
Joe Ainsworth 2021 年 9 月 13 日
worked it out @Walter Roberson thanks for the help

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by