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;
}

I'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?

Oh, okay. This is my own code, there's no errors, I've already run it. But the output is not like what I expected.

I'm supposed to get the values of x,y,z from this codings.
Try inputing the input that I gave earlier, you'll understand what I mean..

Why are you using arrays to solve quadic equation with three unknowns? This is how I was taught to solve them.

I was asked by my professor to do so.
It's for my C++ class, not for maths.

this equations,
2x+3y-z=5
x-y+z=1
3x+2y+2z=6
could be represented in matrix form,

| 2 3 -1 | | X | = | 5 |
| 1 -1 1 | | Y | = | 1 |
| 3 2 2 | | Z | = | 6 |

my codings are to find the values of x, y, z.
but if you run my program, it didn't work out.
idk why, and i'm running out of time to settle this.

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.