write the system of equations in standard form, and solve it with matlab 2a+b-c=1 -a+b+c=2 a+2b=4 in matlab

To write the system of equations in standard form, we need to collect the variables and constants on the same side of each equation.

2a + b - c = 1 -a + b + c = 2 a + 2b = 4

Write it as:

2a + b - c = 1 -a + b + c = 2 a + 2b + 0c = 4

To solve this system of equations in MATLAB, we can define the coefficients in a matrix and the constants in a vector. Then, we can use the backslash operator to solve the system.

main.m
A = [2 1 -1; -1 1 1; 1 2 0];
B = [1; 2; 4];
X = A \ B;
55 chars
4 lines

The result should be:

main.m
X =

    1.0000
    2.0000
    1.0000
38 chars
6 lines

Therefore, the solution to the system of equations is a = 1, b = 2, and c = 1.

related categories

gistlibby LogSnag