Q:

Representing System of Linear Equations using Matrix

belongs to collection: C++ programs on various topics

0

Representing System of Linear Equations using Matrix

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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][1];
	
	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][0]; //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][0]<< "\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
  • Business Based Problems

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
iswlower() function in C++... >>
<< Find intersection of two linked lists using C++ pr...