the given question is
2x+3y-z=5
x-y+z=1
3x+2y+2z=6
i'm supposed to get the values of x,y,z from this coding.
#include <iostream>
#include <cmath>
using namespace std;
void GetMat (float A[10][11], int numrow, int numcol); // to enter elements in a 2 dimension matrix
void DispMat (float A[10][11], int numrow, int numcol); // to display elements in 2 dimension matrix
void MultRow (float A[10][11], int numrow, int numcol, int row, int ct); //ct*row
void SwapRow (float A[10][11], int numrow, int numcol, int row1, int row2); //to swap positions of 2 rows; row1 <-> row2
void AddMat (float A[10][11], int row1, int row2, float ct); //ct*row1+row2
int main()
{
cout<< "\nApplication of Elementary Row Operations on Matrices"<<endl;
cout<< "\nThe matrix is represented in the form of: "<<endl;
cout<< "\t(0,0)x + (0,1)y + (0,2)z = (0,3), a constant"<<endl;
cout<< "\t(1,0)x + (1,1)y + (1,2)z = (1,3), a constant"<<endl;
cout<< "\t(2,0)x + (2,1)y + (2,2)z = (2,3), a constant"<<endl;
int numrow, numcol, matrix[10][11];
float A[10][11];
cout<<"\nNumber of variables: ";
cin>>numrow;
numcol=numrow+1;
GetMat(A, numrow, numcol);
DispMat(A, numrow, numcol);
SwapRow(A, numcol, numrow, 0, 1);
cout<< "\nAfter applying Elementary Row Operations method:\n"<<endl;
DispMat(A, numrow, numcol);
}
void GetMat(float A[10][11], int numrow, int numcol)
{
for (int i=0; i<numrow; i++)
{
for (int j=0; j<numcol; j++)
{
cout<< "Please enter element in "<<i <<","<<j <<" :";
cin>> A[i][j];
}
}
cout<<endl;
}
void DispMat (float A[10][11], int numrow, int numcol)
{
for (int i=0; i<numrow; i++)
{
for (int j=0; j<numcol; j++)
{
if(j==0)
{
cout<<A[i][j]<<"\t";
}
else if (j==1)
{
cout<<A[i][j]<<"\t";
}
else if(j==2 || j==numrow)
{
if (j==numrow)
{
cout<<" | "<<A[i][j]<<"\t";
}
else
{
cout<<A[i][j]<<"\t";
}
}
else if(j==3 || j==numrow){
if (j==numrow)
{
cout<<" | "<<A[i][j]<<"\t";
}
else{cout<<A[i][j]<<"\t";}
}
else if(j==4 || j==numrow)
{
if (j==numrow)
{
cout<<" | "<<A[i][j]<<"\t";
}
else
{
cout<<A[i][j]<<"\t";
}
}
else if(j==5 || j==numrow)
{if (j==numrow){cout<<" | "<<A[i][j]<<"\t";}
else{cout<<A[i][j]<<"\t";}
}
else if(j==6 || j==numrow){if (j==numrow){cout<<" | "<<A[i][j]<<"\t";}
else{cout<<A[i][j]<<"\t";}
}
else if(j==7 || j==numrow){if (j==numrow){cout<<" | "<<A[i][j]<<"\t";}
else{cout<<A[i][j]<<"\t";}
}
else if(j==8 || j==numrow)
{
if (j==numrow)
{
cout<<" | "<<A[i][j]<<"\t";
}
else
{
cout<<A[i][j]<<"\t";
}
}
else if(j==9 || j==numrow)
{
if (j==numrow)
{
cout<<" | "<<A[i][j]<<"\t";
}
else{cout<<A[i][j]<<"\t";}
}
}
cout<<endl;
}
}
void MultRow(float A[10][11], int numrow, int numcol)
{
float ct;
ct=A[numrow][numrow];
for (int i=0; i<numcol; i++)
{
A[numrow][i]=(1/ct)*A[numrow][i];
}
}
void SwapRow(float A[10][11], int numrow, int numcol, int row1, int row2)
{
for (int i=0; i<numcol; i++)
{
for (int j=0; j<numrow; j++)
{
if (i==j)
{
A[j][i] = 1;
}
else
{
A[j][i] = 0;
}
}
}
}
void AddMat(float A[10][11], int numrow, int numcol)
{
float ct= -A[numrow][numcol];
for(int i=0; i<numcol; i++)
{
A[numrow][i]=((ct*A[numcol][i])+A[numrow][i]);
}
DispMat(A, numrow, numcol);
cout<<endl;
}
Alya_1
0
Newbie Poster
Recommended Answers
Jump to PostI'm afraid we'll need more information about the problem you are having in order to give you any advice. Is this your own code, or was it provided by your instructor? Have you tried compiling and running it, and what was the result?
All 4 Replies
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
Alya_1
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Alya_1
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.