# Solve Linear Equation in Matlab Programming

## MATLAB Assignment Help by MATLAB Programming Expert

In mathematics, a system of linear equations (or linear system) is a group of two or more linear equations involving the same set of variables. A linear system in three variables defines a collection of planes. The intersection point is the solution of the equations. The theory of linear systems is the fundamental part of linear algebra, a subject which is used in most parts of mathematics. Computational algorithms for getting the solutions are an important part of numerical linear algebra, and play a crucial role in engineering, physics, chemistry, computer science, and economics. A system of non-linear equations can often be approximated by a linear system, a helpful technique when creating a mathematical model or computer simulation of a relatively complex system.

This section shows you how to solve a system of linear equations with the help of Symbolic Math Toolbox™.

• Solve System of Linear Equations Using linsolve

• Solve System of Linear Equations Using solve

Here is the procedure for solving linear equation in MATLAB

## Declaration of system of equations.

syms x y z

eq1 = 2*x + y + z == 2;

eq2 = -x + y - z == 3;

eq3 = x + 2*y + 3*z == -10;

Conversion of the equations into the form AX = B. Using equationsToMatrix. The second input to equationsToMatrix defines the independent variables in the equations.

[A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z])

solve should be used instead of linsolve if the equations are in the form of expressions and not a matrix of coefficients.

2x+y+z=2

−x+y−z=3

x+2y+3z=−10

## Declare the system of equations.

syms x y z

eq1 = 2*x + y + z == 2;

eq2 = -x + y - z == 3;

eq3 = x + 2*y + 3*z == -10;

Solve the system of equations using solve. The inputs give to function solve are a vector of equations, and a vector of variables to solve the equations for.

sol = solve([eqn1, eqn2, eqn3], [x, y, z]);

xSol = sol.x

ySol = sol.y

zSol = sol.z

xSol =

3

ySol =

1

zSol =

-5

solve returns the solutions in a structure array. To access the solutions, index into the array.