net beans

net beans

Write a JAVA program to read the values of an NxN matrix and print its inverse.

View Answers

December 20, 2010 at 3:51 PM

Hi Friend,

Try the following code:

import java.util.*;
public class InverseMatrix {
  public static void main(String argv[]) {
    int matrix[][]= new int[3][3];
    Scanner input=new Scanner(System.in);
    System.out.println("Enter elements of matrix: ");
    for (int i=0 ; i < matrix.length ; i++)
    for  (int j=0 ; j < matrix[i].length ; j++){
    matrix[i][j] = input.nextInt();
    }
    int len = matrix.length;
    int inverseMatrix[][] = invert(matrix);
      System.out.println("Inverse of Matrix is: ");
    for (int i=0; i<len; ++i) {
      for (int j=0; j<len; ++j){
        System.out.print(inverseMatrix[i][j]+" ");
      }
      System.out.println();
    }
  }

  public static int[][] invert(int a[][]) {
    int n = a.length;
    int x[][] = new int[n][n];
    int b[][] = new int[n][n];
    int index[] = new int[n];
    for (int i=0; i<n; ++i) b[i][i] = 1;

    findInverse(a, index);

    for (int i=0; i<n-1; ++i)
      for (int j=i+1; j<n; ++j)
        for (int k=0; k<n; ++k)
          b[index[j]][k]
            -= a[index[j]][i]*b[index[i]][k];

    for (int i=0; i<n; ++i) {
      x[n-1][i] = b[index[n-1]][i]/a[index[n-1]][n-1];
      for (int j=n-2; j>=0; --j) {
        x[j][i] = b[index[j]][i];
        for (int k=j+1; k<n; ++k) {
          x[j][i] -= a[index[j]][k]*x[k][i];
        }
        x[j][i] /= a[index[j]][j];
      }
    }
  return x;
  }
  public static void findInverse(int a[][],
    int index[]) {
    int n = index.length;
    double c[] = new double[n];

    for (int i=0; i<n; ++i) index[i] = i;

    for (int i=0; i<n; ++i) {
      double c1 = 0;
      for (int j=0; j<n; ++j) {
        double c0 = Math.abs(a[i][j]);
        if (c0 > c1) c1 = c0;
      }
      c[i] = c1;
    }

    int k = 0;
    for (int j=0; j<n-1; ++j) {
      double pi1 = 0;
      for (int i=j; i<n; ++i) {
        double p = Math.abs(a[index[i]][j]);
        p /= c[index[i]];
        if (p > pi1) {
          pi1 = p;
          k = i;
        }
      }
      int temp = index[j];
      index[j] = index[k];
      index[k] = temp;
      for (int i=j+1; i<n; ++i) {
        int pj = a[index[i]][j]/a[index[j]][j];

        a[index[i]][j] = pj;

        for (int l=j+1; l<n; ++l)
          a[index[i]][l] -= pj*a[index[j]][l];
      }
    }
  }
}

Thanks









Related Tutorials/Questions & Answers:
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
Advertisements
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
net beans
net beans  how to calculate electric bill,units,load in net beans and how to insert this calculated bill ,unit and load into database and how this calculate value comes on GUI
NET BEANS
NET BEANS  My problem is when i am going to install net beans then it showing the problem that JDK6 or JDK5 is required for installing net beans IDE,but in actually I've already installed the jdk5,I do not know why
net beans
net beans  Write a JAVA program to read the values of an NxN matrix and print its inverse
net beans
net beans  Write a JAVA program to parse an array and print the greatest value and the number of occurrences of that value in the array. You can initialize the array random values in the program without the need to read them
net beans
net beans  Write a JAVA program to validate the credit card numbers using Luhn Check algorithm. You will need to search the Internet to understand how the algorithm works.   Hi Friend, Try the following code: import
net beans
net beans  Write a JAVA program to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C, D) for each student. Assume there are 5 questions in the test. Your program should finally print
NET BEANS - IDE Questions
NET BEANS  hi i am new to net beans and wants to use net beans 6.5 can any body tell me how can i learn completely about it..if any body have resources abt it plz send me at [email protected]  Hi i am
net beans 4
net beans 4  Write a JAVA program to read an initial two number x1 and x2, and determine if the two numbers are relatively prime. Two numbers are relatively prime. Two numbers are relatively prime if the only common factor
Where is servlet log file in net beans?
Where is servlet log file in net beans?  When you use context.log("some string"); then the string get written into the servlet log file. But where is the servlet log file in netbeans? I am using netbeans 6.9. I can't locate
How to add image in panel as background in net beans IDE?
How to add image in panel as background in net beans IDE?  How to add image in panel as background in net beans IDE
sample application using hibernate and wicket framework in net beans IDE
sample application using hibernate and wicket framework in net beans IDE  where can i get sample applications/ projects using hibernate and wicket framework in net beans IDE
how to run audio files in net beans using j2me
how to run audio files in net beans using j2me  i am running the audioMidlet in net beans. Now where should i place the .wav files inorder to play them
jsp directory created in net beans but not able to access
jsp directory created in net beans but not able to access  File f = new File (config.getServletContext().getRealPath("/") + "artists/" +username); f.mkdir(); File video = new File (config.getServletContext().getRealPath
java Using net beans - Java Beginners
java Using net beans  Dear Sir, I just like to ask why i cant add a data to the answer you have given me last time where i have to pick the data of the student like id , name , class , age & address using netbeans jframe then i
java Using net beans - Java Beginners
java Using net beans  Dear Sir, I just like to ask why i cant add a data to the answer you have given me last time where i have to pick the data of the student like id , name , class , age & address using netbeans jframe then i
java Using net beans - Java Beginners
java Using net beans  Dear Sir, I just like to ask why i cant add a data to the answer you have given me last time where i have to pick the data of the student like id , name , class , age & address using netbeans jframe then i
Java programming or net beans - Java Beginners
Java programming or net beans  Help with programming in Java? Modify the dog class to include a new instance variable weight (double) and the Cat class to include a new instance variable coatColor (string). Add the corresponding
PROJECT ON JAVA NET BEANS AND MYSQL !! PLEASE HELP URGENT
PROJECT ON JAVA NET BEANS AND MYSQL !! PLEASE HELP URGENT  i need a project based on connectivity..it can be based on any of the following topics 1.for calculating income tax. 2.for pf calculation 3.hospital management 4.students
solution for mapping hibernate and pojos from net beans through database
solution for mapping hibernate and pojos from net beans through database  hii I am currently using netbeans 8.0.2 have created small standalone application Employee . i am using hibernate to connect to database which i have
how to generate PDF file using JSP with net beans
how to generate PDF file using JSP with net beans  I am trying to generate PDF file using JSP. I even added itext5.0.6 jar file in library. It shows the following errors... PLz anyone help me. Its urgent.... compile-jsps
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when i start Virtual Keyboard, Means ,if 1st time Button1=''a'' then next login time
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when i start Virtual Keyboard, Means ,if 1st time Button1=''a'' then next login time
Wicket on Net Beans IDE
Wicket on Net Beans IDE     ... the step by step procedure to run Wicket on Net Beans IDE. First of all you must have Wicket Framework on your Net Beans IDE. If you do not have
Java Beans
Java Beans  hii What is Java Beans?   hello,,ADS_TO_REPLACE_1 A Java Bean is a reusable software component that can be manipulated visually in a builder tool
Version of gj-beans>gj-beans dependency
List of Version of gj-beans>gj-beans dependency
Wicket
) and Tapestry frameworks. You can also use the Net Beans IDE for developing... of Apache Wicket framework: Wicket on Net Beans IDE
Enterprise Beans
Enterprise Beans       Enterprise beans are the Java EE server side components that run inside the ejb container... by many users. Enterprise beans are used to perform various types of task like
NET BEAN - IDE Questions
NET BEAN  Thanks for your response actually i am working on struts and other window application. so if you have complete resources abt it then tell me.... and if you have link of this book ""Java EE Development with Net Beans
ModuleNotFoundError: No module named 'beans'
ModuleNotFoundError: No module named 'beans'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'beans' How to remove the ModuleNotFoundError: No module named 'beans'
net_banking
net_banking  hi, I am developing a project on net_banking.. and want to know how to calculate the processing fees on loan(home/vehicle/personal)depending upon loan amount
net beans2
net beans2  Write a JAVA program to find the nearest two points to each other (defined in the 2D-space
sql and .net
sql and .net  I want get coding of connecting data base sql server 2000 to .net please help
.Net - Framework
.Net  i am not getting any dot Net tutorials  hi, http://www.dotnetspider.com/tutorials/AspNet-Tutorials.aspx Thanks
Version of commons-net>commons-net dependency
List of Version of commons-net>commons-net dependency
dot net
dot net  how to open a new window having detailed contents by clicking a marquee text in a page(like news details opening on clicking flash news title) in dot net 2003
Artifacts of gj-beans
List of Artifacts of gj-beans maven depenency
Maven Repository/Dependency: gj-beans | gj-beans
Maven Repository/Dependency of Group ID gj-beans and Artifact ID gj-beans. Latest version of gj-beans:gj-beans dependencies. # Version Release Date You can read more at: Maven
WebORB for .NET
WebORB for .NET       WebORB for .NET is a platform for developing AJAX and Flash-based rich client application and connecting them with .NET objects and XML Web Services. Read full
disadvantages of .net framework - Framework
disadvantages of .net framework  what rae the disadvantages of .net framework
net banking
net banking  hi.... I am developeing a net banking project...and i want coding for following... this module for new loan application... First Name,Last Name, Salaried /business, Current Organization, Resident Address, Office
Maven Dependency gj-beans >> 1.0
You should include the dependency code given in this page to add Maven Dependency of gj-beans >> gj-beans version1.0 in your project
Version of genjava>gj-beans dependency
List of Version of genjava>gj-beans dependency
Version of spring>spring-beans dependency
List of Version of spring>spring-beans dependency
Version of springframework>spring-beans dependency
List of Version of springframework>spring-beans dependency
Version of com.floragunn>ldaptive-beans dependency
List of Version of com.floragunn>ldaptive-beans dependency

Ads