Laxmi
gauss elimination of system of linear equations using java code
Posted in : Java Magazine

Here is my code:

```
import java.util.Scanner;
import java.util.*;

public class gausselimination {
private static final double EPSILON = 1e-10;
int n;int N;
double A[][];
double B[];

public  double[] lsolve(double[][] A, double[] B)
{

for (int p = 0; p < n; p++)
{

int max = p;
for (int i = p + 1; i < N; i++)
{
if (Math.abs(A[i][p]) > Math.abs(A[max][p]))
{
max = i;
}
}
double[] temp = A[p]; A[p] = A[max]; A[max] = temp;
double   t    = B[p]; B[p] = B[max]; B[max] = t;

if (Math.abs(A[p][p]) <= EPSILON) {
throw new RuntimeException("Matrix is singular or nearly singular");
}

for (int i = p + 1; i < N; i++) {
double alpha = A[i][p] / A[p][p];
B[i] -= alpha * B[p];
for (int j = p; j < n; j++) {
A[i][j] -= alpha * A[p][j];
}
}
}

double[] x = new double[n];
for (int i = n - 1; i >= 0; i--)
{
double sum = 0.0;
for (int j = i + 1; j < n; j++)
{
sum += A[i][j] * x[j];
}
x[i] = (B[i] - sum) / A[i][i];
}

System.out.println("the values of unknowns are:-");
for (int i = 0; i < n; i++)
System.out.println("x" + i + "  " +x[i]);

return x;
}

public  void input()
{

double k;
Scanner s=new Scanner(System.in);
System.out.println("enter no of equations ");
N = s.nextInt();

A = new double[N][];
System.out.println("enter no of unknowns");
n=s.nextInt();
for(int l=0;l<N;l++){
A[l]= new double[n];
}
System.out.println("enter the co-efficient of equations");
for(int i=0;i<N;i++){
System.out.println("enter the co-efficient of  equation  "+ (i+1));
for(int j=0;j<n;j++){
k=s.nextDouble();
A[i][j]=k;
}}
B = new double[N];

System.out.println("enter the RHS side of equations");
for(int i=0;i<N;i++){
System.out.println("enter the RHS of  equation  "+ (i+1));

k=s.nextDouble();
B[i]=k;
}
}

public static void main(String args[])

{
gausselimination g = new gausselimination();
g.input();
g.lsolve(g.A, g.B);

}

}
```

Thanks

gauss elimination of system of linear equations using java code
gauss elimination of system of linear equations using java code  Here is my code: import java.util.Scanner; import java.util....); System.out.println("enter no of equations "); N = s.nextInt
Cramers rule for solving equations using java
Cramers rule for solving equations using java  My code: import... s=new Scanner(System.in); System.out.println("enter no of equations of matrix... double[N]; } System.out.println("enter the co-efficient of equations
How to detect system failure using java code - Java Beginners
How to detect system failure using java code  I am doing a project... to detect the process that make failure. I have no idea about the project so please help me. And i need some site to download java source code
linear search - Java Beginners
linear search  How do i use a linear search for a 2 dimensional hard coded array? I need to check the first 2 letters in an item number... friend, Code to solve the problem : public class LinearSearch
Linear Search in Java
Linear Search in Java In this section, we are going to find an element from an array using Linear Searching. Linear searching is a good way to find an element... it is used for small arrays. In the given code, we have allowed the user to enter
JAVA - Java Beginners
JAVA  Hi, I need java code for Gauss-elimination method. I request you to send the code. i am very thankful to you in advance. Regards, Nagarjuna
Linear Regression
Linear Regression  hi........ Can u give me a simple code for Linear Regression in java swings????????? thanks in advance plz reply
linear search
linear search  write a program to find string using linear search
Linear search in java
Linear search in java In this section we will  know, what is linear search and how linear works. Linear search is also known as "sequential... or a string in array. Example of Linear Search in Java:public class LinearSearch
Simple banking system using Java
Simple banking system using Java  I am trying to make a simple banking system that has only 3 interfaces which does not connect to the database... and the other is the branch, the third interface is the main class. Using inheritance
online voting system source code in java
online voting system source code in java  Please send me source code for online voting system in java. please replay as fast as. Thank you
Project on mailing system using Java/JSP
Project on mailing system using Java/JSP  I am making a project on mailing system in Java/JSP. How could I display the inbox messages on the home page of user? Please tell me about how to handle these messages in database
SMS alert system using Java - JSP-Servlet
SMS alert system using Java  Respected Sir/Mam, I need to develop an SMS alert application. Scope of the application: Basically... recipients. This can be developed using any kind of componentsThanks
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
i need attendce management system source code in java
i need attendce management system source code in java  i need attendance management system source code in java
Linear hashing
Linear hashing   hello,, What is linear hashing?   hii, In linear hashing, the table is gradually expanded by splitting the buckets in order until the table has doubled its size
Plotting equations on a cartesian Plane
Plotting equations on a cartesian Plane  Hey, Im sort of a beginner of java, and i at the moment of working on a program that takes the input... on a seperate JPanel. Here is my code: This is Class 1 import java.awt.Color
how to browse the general files which are in system using java? - Java Beginners
how to browse the general files which are in system using java?  how to browse the general files which are in system using java? its just like in ms... and it shows all the word document files, like that i want open all image files using
Product Register System using Java
Product Register System In this section, you will learn how to create product register system. For this, we have categorized the products by code 1 (food), 2... given discount of  0% to product code 1 , 5% product code 2, 15% product
java code using while loop
java code using while loop
how to get an lan system ip and mac address in java code
how to get an lan system ip and mac address in java code  strong text
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
linear sorting
linear sorting  what is linear sorting? can any send me an example   Hi Friend, Try this: import java.util.*; class ArraySort{ public static void sortArray(int arr[]){ Arrays.sort(arr); System.out.println
bird feeder system code
Table's row elimination based on option choosen
Table's row elimination based on option choosen  I have a drop down with yes and no option.if i select yes in a table 2 new rows are shown and if i... help   Please post your code
code for traffic control system simulation
code for traffic control system simulation  any one suggest which functions are used to develop a graphical view to traffic control system using awt and swing
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
attendance management system source code
attendance management system source code  sir i want full ateendance management project please send me source code i am asking so many members... answer so please send code it's very urgent
Java example program to get the operating system's version
check your current system's operating system version by the java code also... Java example program to get the operating system's version... simple to know your operating system's version in java. This program displays
Java get System Locale
Java get System Locale   ... by using the System.getProperty(). This will provide all the properties of the system... of the system. Here is the code of GetSystemLocale.java class
Tutorials