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

4 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 12 Sep. 2021
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 ??

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by