Math Models for Computer Science Let D = [1 -4 8 4 -7 2 0 -1]. If D is the coeff
ID: 3784345 • Letter: M
Question
Math Models for Computer Science
Let D = [1 -4 8 4 -7 2 0 -1]. If D is the coefficient matrix of a homogeneous system of linear equations, write down this system. (Set up only; you don't have to solve it.) If D is the augmented matrix of a system of linear equations, write down this system. (Set up only; you don't have to solve it.) Using the Gauss-Jordan method: Solve the system of equations that you set up in question #1(a). Solve the system of equations that you set up in question #1(b). Solve the systems of equations using the Gauss-Jordan method {3x - 7y = 1, 7y - 6x = 5. {x - 2y - 3z = 2, 2x + y + 4z = 9, x + 3y 7z = 7. {x - 2y - 3z = 2, 2x + y + 4z = 7, x + 3y + 7z = 9.Explanation / Answer
For all the parts, I am writing the code for Gauss Jordan algorithm which can be used to solve these equations.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int variables; // number of variables
cout<<"Enter number of variables: ";
cin>>variables;
float ** A; // it will contain the coeffcients of every equation
A=new float*[variables];
for (int i=0;i<variables;i++)
{
A[i]=new float[variables+1];
}
for (int i=0;i<variables;i++) //storing coefficients
{
for (int j=0;j<variables+1;j++)
cin>>A[i][j];
}
for (int a=0;a<variables;a++) // applying gauss jordan algorithm
{
for(int x=0;x<(variables+1);x++)
{
A[a][x]=A[a][x]/A[a][a];
}
for (int i=0;i<variables;i++)
{
for (int j=0;j<(variables+1);j++)
{
if(a==i) continue;
A[i][j]=A[i][j]-A[a][j]*A[i][a];
}
}
}
cout<<"Answer:"<<' ';
for (int i=0;i<variables;i++)
{
for (int j=0;j<variables+1;j++)
{
cout<<" "<<A[i][j]<<" ";
}
}
return 0;
}