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.*;

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

View Answers









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
Maven dependency for com.kasonchan - equations-monooperation_2.11 version 0.1.1 is released. Learn to use equations-monooperation_2.11 version 0.1.1 in Maven based Java projects
( com.kasonchan - equations-monooperation_2.11 version 0.1.1 ) in their Java project... - equations-monooperation_2.11 version 0.1.1 in Java projects. Follow the step by step tutorial for using the latest version of com.kasonchan - equations
Maven dependency for com.kasonchan - equations-massbalance_2.11 version 0.1.1 is released. Learn to use equations-massbalance_2.11 version 0.1.1 in Maven based Java projects
- equations-massbalance_2.11 version 0.1.1 ) in their Java project if it is based... for using the latest version of com.kasonchan - equations-massbalance_2.11...' Above code will enable the Gradle to down com.kasonchan - equations
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 code using while loop
java code using while loop  
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Linear Regression
Linear Regression  hi........ Can u give me a simple code for Linear Regression in java swings????????? thanks in advance plz reply
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
bird feeder system code
bird feeder system code  i want to know about "bird feeder a business solution system in java" please help me for details. how can develop this system please tell me
linear search
linear search  write a program to find string using linear search
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
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
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
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
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
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
java code using combobox,radiobutton,checkbox
java code using combobox,radiobutton,checkbox  hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
View source code of a html page using java ..
View source code of a html page using java ..  I could find the html source code of a web page using the following program, http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html i could get the html code
Error in MySQL Procedure Using JAVA Code
Error in MySQL Procedure Using JAVA Code  The following Java code (using Connector/J to create a stored procedure on MySQL 5.0) does not execute successfully. Identify the cause and available solutions. statement.execute
java plugin code for nutch using filter indexer
java plugin code for nutch using filter indexer  hello: i want... in the doc.add(name,value) . I don't know what is the error in it. Tthis is the code... = conf; } } I think that the error is in using parsedData but I don't know what I
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
determinant of n*n matrix using java code
determinant of n*n matrix using java code  Here is my code: import java.util.Scanner.*; import java.util.*; public class determinantcode { double A[][]; double m[][]; int N; public input() { Scanner s=new
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
ModuleNotFoundError: No module named 'gauss-lu'
ModuleNotFoundError: No module named 'gauss-lu'  Hi, My Python... 'gauss-lu' How to remove the ModuleNotFoundError: No module named 'gauss-lu... to install padas library. You can install gauss-lu python with following
retrive mails from user using java code - Java Beginners
retrive mails from user using java code   how to retrive mails as user "username"??? using java for ex: class Mail{ private String subject... MailRetriever{ public Mail[] getAllMails(String userName){ //Write code
ModuleNotFoundError: No module named 'single-elimination'
ModuleNotFoundError: No module named 'single-elimination'  Hi, My... named 'single-elimination' How to remove the ModuleNotFoundError: No module named 'single-elimination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'double-elimination'
ModuleNotFoundError: No module named 'double-elimination'  Hi, My... named 'double-elimination' How to remove the ModuleNotFoundError: No module named 'double-elimination' error? Thanks   Hi, In your
Linear hashing
Linear hashing   hello,, What is linear hashing?   hii,ADS_TO_REPLACE_1 In linear hashing, the table is gradually expanded by splitting the buckets in order until the table has doubled its size
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
uploading a file at another system in lan using jsp
uploading a file at another system in lan using jsp  Thanks for the code at "http://www.roseindia.net/jsp/fileupload/Sinleupload.xhtml.shtml". It is working when i gave address of the local system to savefile But if i want
java source code to send group mails using struts2
java source code to send group mails using struts2  code to send group mails using struts2
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
java code to send email using gmail smtp server
java code to send email using gmail smtp server  please send me the java code to send email using gmail smtp server. and how to send verification code
sir plz send the project on quiz system code
sir plz send the project on quiz system code  sir plz send the client server based project in core java database in my sql
source code in java for a program using class - Java Beginners
source code in java for a program using class  Dear sir/madam i want source code in java for following program: WAP which creates a class accountthat stores customer name,account number and type of account.From this derive
how to covert JPG format to Binary formart using java code..
how to covert JPG format to Binary formart using java code..  convert JPG format to Binary formart How can i convert JPG format to Binary format using java code plz help me out
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

Ads