# Representing System of Linear Equations using Matrix

Here, we are going to learn about Representing System of Linear Equations using Matrix.
Submitted by Raja Sethupathi V, on January 28, 2019

A Linear Equation can be represented in matrix form using a:

• Coefficient Matrix
• Variable Matrix and
• Constant Matrix

The System of linear equation in three variables,

```a1x+b1y+c1z=d1
a2x+b2y+c2z=d2
a3x+b3y+c3z=d3
```

The Matrix Representation would be

```a1 b1 c1       xd1
a2 b2 c2y      =d2
a3 b3 c3 zd3
```

We generalize the result of n variable

```a1 b1 c1
a2 b2 c2     __     Coefficient Matrix
a3 b3 c3
x,y,z  are Variable Matrix
d1,d2,d3 are Constant Matrix
```

Consider the System,

```x+2y+3z=4
5x+6y+7z=8
8x+7y+6z=5
```

Then, the coefficient matrix for the above system is

```1 2 3
5 6 7
8 7 6
```

Variable Matrix are X, Y, Z

Constant Matrix are 4,8,5

Representing of linear Matrix in above System is:

```1 2 3 x     4
5 6 7 y     = 8
8 7 6 z     5
```

## C++ program to implement the Representation of Linear Equation in Matrix form

```#include <iostream>
using namespace std;

int main()
{
cout<< "Enter the number of variables in the equations: ";
int n;

cin>>  n;
char var = 'x';
int a[n][n],b[n];

for (int i = 0; i< n; i++)
{
for (int j = 0; j < n; j++)
{
cin>> a[i][j];   //Get the Matrix values
}
cin>> b[i]; //Get the constant values
}

cout<< "\nLinear Equation in Matrix representation is: \n";
for (int i = 0; i< n; i++)
{
for (int j = 0; j < n; j++)
{
cout<<" "<< a[i][j]; //print the matrix values
}
//print the variable and constant values
cout<< "  " <<static_cast<char>(var) << "  =  " << b[i]<< "\n";
var++;
}

return 0;
}
```

Output

```Enter the number of variables in the equations:
3
1 2 3 4
5 6 7 8
8 7 6 5
Linear Equation in Matrix representation is:
1 2 3 x   =    4
5 6 7 y   = 8
8 7 6 z   =   5
```

Applications:

Systems of Linear Equations can be used to solve some Real – Time Problems:

• Solving a Mixture problems
• Distance Rate Time problems

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates