# Converting system of equations to form Ax=b

5 views (last 30 days)
aliza mustafa on 14 Sep 2022
Commented: aliza mustafa on 14 Sep 2022
Hi,
I have the following system of equations:
- t + w + x = 100 eq(1)
t - u = 100 eq(2)
v + w - y - z = 0 eq(3)
u + v = 40 eq(4)
Suppose I have t = 100 and w + y+ z = 100, then I want to write this system of equations in the form Ax = b.
This is how I tried to do it:
eq(1): -100 + w + x = 100
=> w + x = 200
eq(2): t - u = 100
=> 100 - u = 100
=> u = 0
eq(3): v + w - y - z = 0
=> v + w- (y+z) = 0
=> v + w - (100 - w) = 0
=> v + 2w = 100
eq(4): u + v = 40
If I put u = 0 of eq(2) in it, I get:
v = 40
If I put v=40 in eq(3), I get:
w = 30
If I put it w=30 in eq(1), I get:
x = 170
I am stuck here. I am just not understanding what to do next to convert this all in system Ax=b. I am not sure even if I have done it in correct way. Can you please guide me in this all? Any help will be highly appreciated.

John D'Errico on 14 Sep 2022
Edited: John D'Errico on 14 Sep 2022
help equationsToMatrix
--- help for sym/equationsToMatrix --- equationsToMatrix Convert linear equations to matrix notation. [A,b] = equationsToMatrix([eq1,eq2,eq3,...],[x1,x2,...,xn]) converts the equations eq1,eq2,eq3,... to matrix notation. Equations need to be linear in the variables specified as second argument. eq1,eq2,eq3,... can be SYM equations or simply SYM objects. In case eq1,eq2,eq3,... are generic SYM objects, they will be interpreted as left sides of equations, whose right sides are equal to 0. The equations just need to be linear in the given variables, it does not play a role how they are ordered or on which side of the equations the unknowns show up. [A,b] = equationsToMatrix([eq1,eq2,eq3,...]) converts the equations [eq1,eq2,eq3,...] to matrix notation. Equations need to be linear in all variables of the equations. The system is interpreted as a linear system of equations in the variables symvar([eq1,eq2,eq3,...]). [A,b] = equationsToMatrix(eq1,eq2,eq3,...,x1,x2,...,xn) does the same as equationsToMatrix([eq1,eq2,eq3,...],[x1,x2,...,xn]). [A,b] = equationsToMatrix(eq1,eq2,eq3,...) does the same as equationsToMatrix([eq1,eq2,eq3,...]). If you do not assign the output to variables A and b or just assign the output to a single variable, only the matrix A will be returned. Examples: syms x y z eq1 = x + y + z eq2 = x - 2*y - 5*z == 0 eq3 = x - z == 1 [A,B] = equationsToMatrix([eq1,eq2,eq3],[x,y,z]) A = equationsToMatrix([eq1,eq2,eq3],[x,y,z]) [A,B] = equationsToMatrix(eq1,eq2,eq3,x,y,z) A = equationsToMatrix(eq1,eq2,eq3,x,y,z) [A,B] = equationsToMatrix([eq1,eq2,eq3]) A = equationsToMatrix([eq1,eq2,eq3]) [A,B] = equationsToMatrix(eq1,eq2,eq3) A = equationsToMatrix(eq1,eq2,eq3) See also LINSOLVE, MLDIVIDE, SYM/LINSOLVE, SYM/MLDIVIDE, SOLVE, DSOLVE Documentation for sym/equationsToMatrix doc sym/equationsToMatrix
For example.
syms x y
E1 = x + y == 1
E1 =
E2 = x - y == 2
E2 =
[A,B] = equationsToMatrix(E1,E2,[x,y])
A =
B =
aliza mustafa on 14 Sep 2022
This is such a great help. Thank you soo much.

### Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by