This is part of a homework assignment that I cant seem to solve.
Create, save and run a script that solves the following set of equations for user-supplied values of a, b, and c. Check your script with the values of a=95, b=-50, and c=145. Set of equations are:
7x+14y-6z=a
12x+5y+9z=b
-5x+7y+15z=c
My code right now is
an1 = 'Give me a'
a = input(an1);
an2 = 'Give me b'
b = input(an2);
an3 = 'Give me c'
c = input(an3);
syms x y z
eq1 = (7*x)+(14*y)-(6*z)== a;
eq2 = (12*x)+(5*y)+(9*z)== b;
eq3 = (-5*x)+(7*y)+(15*z)== c;
x,y,z = solve(eq1,eq2,eq3, x,y,z)
x,y,z = solve(eq1,eq2,eq3, x,y,z)
z,y,z = solve(eq1,eq2,eq3, x,y,z)
Does anyone know how I could find the values of x, y, and z from these functions?
Final Code, thanks for the help Image Analyst
an1 = 'Give me a'
a = input(an1);
an2 = 'Give me b'
b = input(an2);
an3 = 'Give me c'
c = input(an3);
X = [7, 14, -6;
12, 5, 9;
-5, 7, 15]
Y = [a; b; c]
coefficients = X \ Y

 Accepted Answer

Image Analyst
Image Analyst on 3 Nov 2019
Edited: Image Analyst on 3 Nov 2019
Try a matrix division:
% 7x+14y-6z=a
% 12x+5y+9z=b
% -5x+7y+15z=c
X = [7, 14, -6;
12, 5, 9;
-5, 7, 15]
Y = [11; 22; 33] % Whatever it may be.
% Solve for the coefficients, using a least squares approach.
coefficients = X \ Y
% Double check to see if we get back a, b, and c
a2 = 7 * coefficients(1) + 14 * coefficients(2) - 6 * coefficients(3)
b2 = 12 * coefficients(1) + 5 * coefficients(2) + 9 * coefficients(3)
c2 = -5 * coefficients(1) + 7 * coefficients(2) + 15 * coefficients(3)

5 Comments

That unfortunately didn't work.
I actually ran it, and it did work.
X =
7 14 -6
12 5 9
-5 7 15
Y =
11
22
33
coefficients =
0.070967741935484
1.41935483870968
1.56129032258065
a2 =
11
b2 =
22
c2 =
33
Did you put back in the questions asking for a, b, and c, and uncomment the line?
Y = [a; b; c] % Whatever the user enters.
% Y = [11; 22; 33] % For example, use these values...
What values did you put for a, b, and c that caused it not to work?
This is the code after plugging it in, I'm guessing I mdid it wrong.
an1 = 'Give me a'
a = input(an1);
an2 = 'Give me b'
b = input(an2);
an3 = 'Give me c'
c = input(an3);
syms x y z
%(7*x)+(14*y)-(6*z)== a;
%(12*x)+(5*y)+(9*z)== b;
% (-5*x)+(7*y)+(15*z)== c;
X = [7, 14, -6;
12, 5, 9;
-5, 7, 15]
% Y = [a; b; c] % Whatever the user enters.
Y = [a; b; c] % For example, use these values...
% Solve for the coefficients, using a least squares approach.
coefficients = x \ y
I corrected the missuse of your code and got the answer
X =
7 14 -6
12 5 9
-5 7 15
Y =
95
-50
145
coefficients =
-9.7742
12.0161
0.8011
Thank you for the help.
MATLAB is case sensitive so
coefficients = X \ Y
is not the same as
coefficients = x \ y

Sign in to comment.

More Answers (1)

Sandeep Raut
Sandeep Raut on 30 Sep 2020
Find the values of x and y using MATLAB commands, also solve the equation and justify how your commands work
4y+3x=100
4y−19x=12

1 Comment

How is this an answer to Benjamin's question?

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!