Question

design a program that solves matrices by the gauss-jordan method use the object-oriented language c ++

design a program that solves matrices by the gauss-jordan method use the object-oriented language c ++

Homework Answers

Answer #1

// C++ program that solves matrices by the gauss-jordan method
// Elimination_Method
#include <bits/stdc++.h>
using namespace std;

#define M 10

// Function to print_the_matrix
void PrintMatrix(float a[][M], int n)
{
   for (int i = 0; i < n; i++) {
       for (int j = 0; j <= n; j++)
       cout << a[i][j] << " ";
       cout << endl;
   }
}

// function to reduce_matrix to reduced
// row_echelon form.
int PerformOperation(float a[][M], int n)
{
   int i, j, k = 0, c, flag = 0, m = 0;
   float pro = 0;
  
   // Performing elementary_operations
   for (i = 0; i < n; i++)
   {
       if (a[i][i] == 0)
       {
           c = 1;
           while ((i + c) < n && a[i + c][i] == 0)
               c++;             
           if ((i + c) == n) {
               flag = 1;
               break;
           }
           for (j = i, k = 0; k <= n; k++)
               swap(a[j][k], a[j+c][k]);
       }

       for (j = 0; j < n; j++) {
          
           // Excluding all i == j
           if (i != j) {
              
               // Converting Matrix to reduced row
               // echelon form(diagonal matrix)
               float pro = a[j][i] / a[i][i];

               for (k = 0; k <= n; k++)                 
                   a[j][k] = a[j][k] - (a[i][k]) * pro;                 
           }
       }
   }
   return flag;
}

// Function to print the desired_result
// if unique_solutions exists, otherwise
// prints no_solution or infinite_solutions
// depending upon the input_given.
void PrintResult(float a[][M], int n, int flag)
{
   cout << "Result is : ";

   if (flag == 2)     
   cout << "Infinite Solutions Exists" << endl;     
   else if (flag == 3)     
   cout << "No Solution Exists" << endl;
  
  
   //solution by dividing constants by
   // their respective_diagonal_elements
   else {
       for (int i = 0; i < n; i++)         
           cout << a[i][n] / a[i][i] << " ";         
   }
}

// To check whether infinite_solutions
// exists or no_solution exists
int CheckConsistency(float a[][M], int n, int flag)
{
   int i, j;
   float sum;
  
   // flag == 2 for infinite_solution
   // flag == 3 for No_solution
   flag = 3;
   for (i = 0; i < n; i++)
   {
       sum = 0;
       for (j = 0; j < n; j++)         
           sum = sum + a[i][j];
       if (sum == a[i][j])
           flag = 2;         
   }
   return flag;
}

// Driver code
int main()
{
   float a[M][M] = {{ 0, 2, 1, 4 },
                   { 1, 1, 2, 6 },
                   { 2, 1, 1, 7 }};
                  
   // Order of Matrix(n)
   int n = 3, flag = 0;
  
   // Performing Matrix-transformation
   flag = PerformOperation(a, n);
  
   if (flag == 1)     
       flag = CheckConsistency(a, n, flag);     

   // Printing Final-Matrix
   cout << "Final Augumented_Matrix is : " << endl;
   PrintMatrix(a, n);
   cout << endl;
  
   // Printing Solutions(if exist)
   PrintResult(a, n, flag);

   return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use Gauss-Jordan method (augmented matrix method) to solve the following systems of linear equations. Indicate whether...
Use Gauss-Jordan method (augmented matrix method) to solve the following systems of linear equations. Indicate whether the system has a unique solution, infinitely many solutions, or no solution. Clearly write the row operations you use. (a) x − 2y + z = 8 2x − 3y + 2z = 23 − 5y + 5z = 25 (b) x + y + z = 6 2x − y − z = 3 x + 2y + 2z = 0
Use Gauss-Jordan method (augmented matrix method) to solve the following systems of linear equations. Indicate whether...
Use Gauss-Jordan method (augmented matrix method) to solve the following systems of linear equations. Indicate whether the system has a unique solution, infinitely many solutions, or no solution. Clearly write the row operations you use. (a) (5 points) x + y + z = 6 2x − y − z = 3 x + 2y + 2z = 0 (b) (5 points) x − 2y + z = 4 3x − 5y + 3z = 13 3y − 3z =...
Use the Gauss-Jordan method with pivoting to find the inverse of the coefficient matrix for the...
Use the Gauss-Jordan method with pivoting to find the inverse of the coefficient matrix for the system of equations given. Hint: Keep values as fractions rather than estimating using decimal points throughout. When reporting your answer, convert to decimal form. Approximately halfway through calculating the inverse, just before multiplying Row 3 by a scalar so that A(3,3) becomes 1, what is the value of A(3,3)? Answer is 0.1 On the last calculation, just before multiplying Row 1 by a scalar so that...
2. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit...
2. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit in use any other method. Use exactly the notation we used in class and in the text. Indicate whether the system has a unique solution, no solution, or infinitely many solutions.In the latter case,present the solutions in parametric form x+2y+3z=7 -12z=24 -10y-5z=-40
4. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit...
4. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit in use any other method. Use exactly the notation we used in class and in the text. Indicate whether the system has a unique solution, no solution, or infinitely many solutions. In the latter case, present the solutions in parametric form. 3x + 6y + 3z = -6 -2x -3y -z = 1 x +2y + z = -2
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
PLEASE WORK THESE OUT!! A) Solve the system of linear equations using the Gauss-Jordan elimination method....
PLEASE WORK THESE OUT!! A) Solve the system of linear equations using the Gauss-Jordan elimination method. 2x + 10y = −1 −6x + 8y = 22 x,y=_________ B) If n(B) = 14, n(A ∪ B) = 30, and n(A ∩ B) = 6, find n(A). _________ C) Solve the following system of equations by graphing. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, enter INFINITELY MANY.) 3x + 4y = 24 6x + 8y...
A Business Rule in terms of an Object Oriented Systems Design project can be defined as...
A Business Rule in terms of an Object Oriented Systems Design project can be defined as the following… 1. All economic decisions listed in one use case requirement that is to be met by the system to be developed. 2. It defines or constrains one aspect of the business that is intended to assert business structure or influence the behavior of the business. 3. All managerial use case interfaces to the system incuding decision making logic that is coded in...
Has to be written in C#! Write a program that includes an Employee class that can...
Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT