Purchase Solution

Programming > Java

Not what you're looking for?

Ask Custom Question

Applet program that finds an inverse matrix

Applet program that accepts a 2x2 matrix and finds its inverse matrix if any. It seems easy, but I am having a problem getting it to work.

Purchase this Solution

Solution Preview

Dear my friend
We are so happy that you have choosed Brainmass to get help.
We are so interested to help you and your friend to get what you need.
I have found this code in my files for you, which is completely usefull for any operaion on metices. I hope to be usefull.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class MatrixCalculator {

private boolean DEBUG = true;

private boolean INFO = true;

private static int max = 100;

private static int decimals = 3;

private JLabel statusBar;

private JTextArea taA, taB, taC;

private int iDF = 0;

private int n = 4;

private static NumberFormat nf;

public Component createComponents() {

/* == MATRICES == */
taA = new JTextArea();
taB = new JTextArea();
taC = new JTextArea();

JPanel paneMs = new JPanel();
paneMs.setLayout(new BoxLayout(paneMs, BoxLayout.X_AXIS));
paneMs.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
paneMs.add(MatrixPane("Matrix A", taA));
paneMs.add(Box.createRigidArea(new Dimension(10, 0)));
paneMs.add(MatrixPane("Matrix B", taB));
paneMs.add(Box.createRigidArea(new Dimension(10, 0)));
paneMs.add(MatrixPane("Matrix C", taC));

/* == OPERATION BUTTONS == */
JPanel paneBtn = new JPanel();
paneBtn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
paneBtn.setLayout(new GridLayout(3, 3));
JButton btnApB = new JButton("A + B = C");
JButton btnAmB = new JButton("A * B = C");
JButton btnBmA = new JButton("B * A = C");
JButton btnAdjA = new JButton("adjoint(A) = C");
JButton btnInvA = new JButton("inverse(A) = C");
JButton btnInvB = new JButton("inverse(B) = C");
JButton btnTrnsA = new JButton("transpose(A) = C");
JButton btnDetA = new JButton("determ(A) = C");
JButton btnDetB = new JButton("determ(B) = C");
paneBtn.add(btnApB);
paneBtn.add(btnAmB);
paneBtn.add(btnBmA);
paneBtn.add(btnAdjA);
paneBtn.add(btnInvA);
paneBtn.add(btnInvB);
paneBtn.add(btnTrnsA);
paneBtn.add(btnDetA);
paneBtn.add(btnDetB);

/* == ADD BUTTON Listeners == */
btnApB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
DisplayMatrix(AddMatrix(ReadInMatrix(taA),
ReadInMatrix(taB)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
});

btnAmB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
DisplayMatrix(MultiplyMatrix(
ReadInMatrixNotSquare(taA),
ReadInMatrixNotSquare(taB)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
});

btnBmA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
DisplayMatrix(MultiplyMatrix(ReadInMatrixNotSquare(taB),
ReadInMatrixNotSquare(taA)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
});

btnInvA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
DisplayMatrix(Inverse(ReadInMatrix(taA)), taC);
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
});

btnInvB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Networking Questions

This quiz consists of some basic networking questions.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.