Question

In: Computer Science

design a program that solves matrices by the method of gauss-seidel use the object-oriented language c...

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

Solutions

Expert Solution

Gauss Seidel Method

Gauss-Seidel Method is used to solve the linear system Equations. This method is named after the German Scientist Carl Friedrich Gauss and Philipp Ludwig Siedel. It is a method of iteration for solving n linear equation with the unknown variables. This method is very simple and uses in digital computers for computing.

PROGRAM TO SOLVE MATRICES BY METHOD OF GAUSS-SEIDAL:

#include<iostream>
#include<conio.h>
using namespace std;
int main(void)
{
float a[10][10], b[10], x[10], y[10];
int n = 0, m = 0, i = 0, j = 0;
cout << "Enter size of 2d array(Square matrix) : ";
cin >> n;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << "Enter values no :(" << i << ", " << j << ") ";
cin >> a[i][j];
}
}
cout << "\nEnter Values to the right side of equation\n";
for (i = 0; i < n; i++)
{
cout << "Enter values no :(" << i << ", " << j << ") ";
cin >> b[i];
}
cout << "Enter initial values of x\n";
for (i = 0; i < n; i++)
{
cout << "Enter values no. :(" << i<<"):";
cin >> x[i];
}
cout << "\nEnter the number of iteration : ";
cin >> m;
while (m > 0)
{
for (i = 0; i < n; i++)
{
y[i] = (b[i] / a[i][i]);
for (j = 0; j < n; j++)
{
if (j == i)
continue;
y[i] = y[i] - ((a[i][j] / a[i][i]) * x[j]);
x[i] = y[i];
}
printf("x%d = %f ", i + 1, y[i]);
}
cout << "\n";
m--;
}
return 0;
}

output:

output with different array size:


Related Solutions

% Solves Ax = b by Gauss-Seidel method with relaxation. % USAGE: [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon) %...
% Solves Ax = b by Gauss-Seidel method with relaxation. % USAGE: [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon) % INPUT: % func = handle of function that returns improved x using % x = starting solution vector % maxIter = allowable number of iterations (default is 500) % epsilon = error tolerance (default is 1.0e-9) % OUTPUT: % x = solution vector % numIter = number of iterations carried out % omega = computed relaxation factor if nargin < 4; epsilon = 1.0e-9;...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
Use the Gauss-Seidel method (a) without relaxation and (b) with relaxation (l 5 0.95) to solve...
Use the Gauss-Seidel method (a) without relaxation and (b) with relaxation (l 5 0.95) to solve the following system to a tolerance of es 5 5%. If necessary, rearrange the equations to achieve convergence. 23x1 1 x2 1 12x3 5 50 6x1 2 x2 2 x3 5 3 6x1 1 9x2 1 x3 5 40
When should you use and object-oriented language over a procedural language and vice versa?
When should you use and object-oriented language over a procedural language and vice versa?
The Gauss-Seidel method as an iterative technique often refers to an improved version of the Jacobi...
The Gauss-Seidel method as an iterative technique often refers to an improved version of the Jacobi method, since the Gauss-Seidel method generally achieves a faster convergence. Describe the difference between the Gauss-Seidel and Jacobi methods.
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has...
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has shows that In implementing SOR method in MATLAB, one should not calculate Tw and cw by formulas Tw = (D -wL)^(-1)[(1-w)D+wU)] and Cw = w(D-wL)^(-1)b , where w stands for omega and using MATLAB's built-in inv function, since this function requires O(n^3) flops and therefore the whole matter loses its point. I have tried for many times but I can't get the correct answers....
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or...
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or Gauss-Siedel iteration for ten iterations with a MAT-LAB function. * A= [5, -1,0;-1,5,-1;0,-1,5] , B=[9;4;-6]
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or...
A) Use Jacobi or Gauss-Seidel iteration and perform three iterations by hand. B) Use Jacobi or Gauss-Siedel iteration for ten iterations with a MAT-LAB function. * A= [10 -2 1;-2 10 -2;-2 -5 10] , B=[9;12;18]
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
What are CRC cards and use-case scenarios used for in object-oriented analysis and design?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT