Can you change(write) this code a little differrent? and this is the question but pls change this code Write a computer program for Gauss elimination method using C programming language. Decide the number of significant figures yourselves. While writing your program, consider the effects of the number of significant figures, pivoting, scaling and do not forget to check if the system is ill conditioned.   #include #include

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Hi, Can you change(write) this code a little differrent? and this is the question but pls change this code

Write a computer program for Gauss elimination method using C programming language. Decide the number of significant figures yourselves. While writing your program, consider the effects of the number of significant figures, pivoting, scaling and do not forget to check if the system is ill conditioned.

 

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,j,k;// initializing variables
cout<<"\nEnter the no. of equations\n";
cin>>n; //input the no. of equations
float matrix[n][n+1],x[n]; //declare an array to store the elements of augmented-matrix
cout<<"\nEnter the elements of the augmented-matrix row-wise:\n";
for (i=0;i<n;i++)// taking the input from the user
for (j=0;j<=n;j++)
cin>>matrix[i][j];//input the elements of array
for (i=0;i<n;i++) //Pivotisation for the given matrix
for (k=i+1;k<n;k++)
if (abs(matrix[i][i])<abs(matirx[k][i]))// condition for checking Pivotisation
for (j=0;j<=n;j++)
{
double temp=matrix[i][j];// performing swap
matrix[i][j]=matrix[k][j];
matrix[k][j]=temp;
}
cout<<"\nThe matrix after Pivotisation is:\n";
for (i=0;i<n;i++) //print the new matrix
{
for (j=0;j<=n;j++)
cout<<matrix[i][j]<<setw(16);
cout<<"\n";
}
for (i=0;i<n-1;i++) //loop to perform the gauss elimination
for (k=i+1;k<n;k++)
{
double t=matrix[k][i]/matrix[i][i];
for (j=0;j<=n;j++)
matrix[k][j]=matrix[k][j]-t*matrix[i][j]; //make the elements below the pivot elements equal to zero or elimnate the variables
}

cout<<"\n\nThe matrix after gauss-elimination is as follows:\n";
for (i=0;i<n;i++) //print the new matrix
{
for (j=0;j<=n;j++)
cout<<matrix[i][j]<<setw(16);
cout<<"\n";
}
for (i=n-1;i>=0;i--)//back-substitution
{ //x is an array whose values correspond to the values of x,y,z..
x[i]=matrix[i][n]; //make the variable to be calculated equal to the rhs of the last equation
for (j=i+1;j<n;j++)
if (j!=i) //then subtract all the lhs values except the coefficient of the variable whose value is being calculated
x[i]=x[i]-matrix[i][j]*x[j];
x[i]=x[i]/matrix[i][i]; //now finally divide the rhs by the coefficient of the variable to be calculated
}
cout<<"\nThe values of the variables are \n";
for (i=0;i<n;i++)
cout<<x[i]<<endl;// Print the values of x, y,z
return 0;
}

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Algebraic Expression
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education