Hello! I need some help solving linear equations for the coefficients

26 visualizaciones (últimos 30 días)
Xenon Asuncion el 5 de Sept. de 2020
Comentada: Álvaro el 1 de Dic. de 2023
This is the question:
Liz buys three apples, a dozen bananas, and one cantaloupe for \$2.36.
Bob buys a dozen apples and two cantaloupe for \$5.26.
Carol buys two bananas and three cantaloupe for \$2.77.
How much do single pieces of each fruit cost?
This is my work so far:
%Set the variables to be used in the problem.
syms x y z
%Input the equations given in the problem.
Equation_1 = input('Input the given equation. To input the total amount use "==". ')
Equation_2 = input('Input the given equation. To input the total amount use "==". ')
Equation_3 = input('Input the given equation. To input the total amount use "==". ')
%Transform the linear equation into a matrix form
[A, B] = equationToMatrix ([Equation_1, Equation_2, Equation_3], [x, y, z])
I tried running it, but it errors when I put the equation. Thanks in advance!
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Respuestas (3)

David Hill el 5 de Sept. de 2020
a=[3 12 1;12 0 2;0 2 3]\[2.36;5.26;2.77];
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Álvaro el 30 de Nov. de 2023
Editada: Image Analyst el 30 de Nov. de 2023
Hi, I tried the following code (I do not know why, but one of the prices is less than zero)
x = [ 3 12 1; 0 12 2; 0 2 3];
y = [2.36; 5.26; 2.77];
v = linsolve(x,y)
v = 3×1
-0.7300 0.3200 0.7100
2 comentariosMostrar NingunoOcultar Ninguno
Walter Roberson el 30 de Nov. de 2023
Bob bought 0 apples??
Álvaro el 1 de Dic. de 2023
'-'

Iniciar sesión para comentar.

Image Analyst el 30 de Nov. de 2023
@Álvaro you should have done it like this:
% Liz buys three apples, a dozen bananas, and one cantaloupe for \$2.36.
% Bob buys a dozen apples and two cantaloupe for \$5.26.
% Carol buys two bananas and three cantaloupe for \$2.77.
% How much do single pieces of each fruit cost?
% 2.36 = 3 * a + 12 * b + c
% 5.26 = 12 * a + 0 * b + 2 * c
% 2.77 = 0 * a + 2 * b + 3 * c
% totals = quantities * individualPrices
% Create arrays that describe the set of linear equations:
totals = [2.36; 5.26; 2.77]
totals = 3×1
2.3600 5.2600 2.7700
quantities = [3, 12, 1;
12, 0, 2;
0, 2, 3]
quantities = 3×3
3 12 1 12 0 2 0 2 3
individualPrices = linsolve(quantities,totals)
individualPrices = 3×1
0.2900 0.0500 0.8900
% Double check:
totalsCheck = quantities * individualPrices
totalsCheck = 3×1
2.3600 5.2600 2.7700
1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Álvaro el 1 de Dic. de 2023
Now I understand, thank you very much

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by