# Gauss program

• 05-02-2014, 02:54 PM
Ratheo
Gauss program
Hello.
I have a big problem with writing Gauss Elimination in Java code. This is my homework, it's true. But I want to learn this, and I don't know how to bite this. I will be very gratefull if you give me some advices or hints. I must realise some points:
1) Create new class - Gauss Elimination with two attributes (table A (nxn) and table B with vector (n));
2) Add new method "eliminate" which transform matrix A and parametr vectors B ;
3) Add new method "solve" which calculate inverse substitution.

Thanks for all :)
• 05-03-2014, 02:42 AM
Norm
Re: Gauss program
What have you tried?

What specific questions do you have?
• 05-03-2014, 12:07 PM
Ratheo
Re: Gauss program
This is my beginning :)
Code:

```public class GaussElimination {               double[][] A;                    double[]  b;                              public void eliminate(double[][] A, double[] b)             { </code> I have tried this code: <code>  public void GaussianElim(double[][] A, double[] b)             {                                         for (i = 0; i < n; i++)                             {  // Process row i                                                   /* ---------------------                                   (A) Select pivot                                   --------------------- */                               pivot = A[i][i];                                                   /* ---------------------                                   (B) Normalize row i                                   --------------------- */                               for (j = 0; j < n; j++)                                   A[i][j] = A[i][j]/pivot;                                                   b[i] = b[i]/pivot;                                                   /* ---------------------                                   (C) Sweep using row i                                   --------------------- */                               for (k = 0; k < n; k++)                               {                                   if ( k != i )                                   {                                     factor = A[k][i];                                                         for (j = 0; j < n; j++)                                         A[k][j] = A[k][j] - factor*A[i][j];                                                         b[k] = b[k] - factor*b[i];                         } <```
>
But I don't understand this loops. Where can I start? I don't understand these methods :(
• 05-03-2014, 02:47 PM
Norm
Re: Gauss program
Quote:

I don't understand this loops
Look at the tutorial for a descritpion of how a for loop works:
The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

I don't know anything about Gauss, it is not a part of java. Java is a programming language that can be used to solve lots of different problems.
If you have any specific questions about java programming, post them.
• 05-03-2014, 04:51 PM
JosAH
Re: Gauss program
Note that Gaussian elimination (and Gauss/Jordan elimination) is more complicated if the pivot element (the element on the diagonal of the matrix) is zero. You need to permute the rows (or columns) to get a non-zero element in that position.

kind regards,

Jos