\(
\newcommand{\blah}{blah-blah-blah}
\newcommand{\eqb}[1]{\begin{eqnarray*}#1\end{eqnarray*}}
\newcommand{\eqbn}[1]{\begin{eqnarray}#1\end{eqnarray}}
\newcommand{\bb}[1]{\mathbf{#1}}
\newcommand{\mat}[1]{\begin{bmatrix}#1\end{bmatrix}}
\newcommand{\nchoose}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array}\right)}
\newcommand{\defn}{\stackrel{\vartriangle}{=}}
\newcommand{\rvectwo}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array}\right)}
\newcommand{\rvecthree}[3]{\left(\begin{array}{r} #1 \\ #2\\ #3\end{array}\right)}
\newcommand{\rvecdots}[3]{\left(\begin{array}{r} #1 \\ #2\\ \vdots\\ #3\end{array}\right)}
\newcommand{\vectwo}[2]{\left[\begin{array}{r} #1\\#2\end{array}\right]}
\newcommand{\vecthree}[3]{\left[\begin{array}{r} #1 \\ #2\\ #3\end{array}\right]}
\newcommand{\vecdots}[3]{\left[\begin{array}{r} #1 \\ #2\\ \vdots\\ #3\end{array}\right]}
\newcommand{\eql}{\;\; = \;\;}
\definecolor{dkblue}{RGB}{0,0,120}
\definecolor{dkred}{RGB}{120,0,0}
\definecolor{dkgreen}{RGB}{0,120,0}
\)
Assignment 2
Part I: Pen-and-paper
- Suppose that the inverse of a square matrix is defined using
only left multiplication: define \({\bf A}^{-1}\) as the matrix
with the property that \({\bf A}^{-1} {\bf A} = {\bf I}\).
In this exercise, you will prove that this implies that
\({\bf A} {\bf A}^{-1} = {\bf I}\) using two steps:
- First show that the identity matrix \({\bf I}\) is
unique. That is, if there's any other matrix \({\bf J}\)
such that \({\bf A J} = {\bf A} = {\bf J A}\), then
\({\bf I} = {\bf J}\).
- Use the above fact and the associativity of
matrix multiplication (which is a hint too)
to establish \({\bf A} {\bf A}^{-1} = {\bf I}\).
Part II: Programming
The next set of functionality to build into your library is
to solve equations.
- You will be adding code to your implementation of
the LinTool interface
that you began in the earlier assignment.
Thus, if your username
is alice, your tool is called
AliceLinTool.
- Create a directory called alice_a2 for this
assignment, if your username is alice.
- For this assignment, you will implement the following methods:
// Set L.ref, L.isPivotColumn, L.pivotRow:
public abstract LinResult computeREF (double[][] A, double[] b);
// Set L.rref, L.isPivotColumn, L.pivotRow, L.rank:
public abstract LinResult computeRREF (double[][] A, double[] b);
// Set L.ref, L.isPivotColumn, L.pivotRow,
// L.rank, L.x, L.solutionExists, L.isUniqueSolution, L.x
public abstract LinResult solveFromREF (double[][] A, double[] b);
// In addition to all that was set in solveFromREF,
// also set L.rref, L.Ainv for the next two methods:
public abstract LinResult solveFromRREF (double[][] A, double[] b);
public abstract LinResult inverse (double[][] A);
// Complex vector operations:
public abstract ComplexNumber[] add (ComplexNumber[] u, ComplexNumber[] v);
public abstract double norm (ComplexNumber[] v);
public abstract ComplexNumber[] scalarProduct (ComplexNumber alpha, ComplexNumber[] v);
public abstract ComplexNumber dotProduct (ComplexNumber[] u, ComplexNumber[] v);
// Note: dot product is the Hermitian dot
// product: the one we defined for complex numbers in Module-4
- The rather straightforward (except for dot-product)
complex vector operations are described in Module 4.
- Note: you are not using your implementation of a
ComplexNumber
but instead should assume that you are getting some
class that extends it.
- Note:
- This assignment is really about computing the REF and RREF as shown
in Module 5.
- Although there are five methods above, you should really
compute the REF/RREF in a separate method and call that
from your five methods above. This way, you can set all the
needed variables in
LinResult
in one place and return all that's needed (and perhaps more) in
LinResult
- The methods will need to return multiple things. Because
Java methods can have only one return value, we will use an
object to hold multiple different things.
This is the purpose of
LinResult.
- Thus, in your code, you will create an instance of
LinResult.
and use it along the lines of
// .... inside some method ....
// Make an instance of LinResult
LinResult L = new LinResult ();
// Put stuff in the object
L.x = ...
L.ref = ...
L.rref = ...
// return
return L;
- So, what are you expected to return?
-
L.ref, the REF
-
L.rref, the RREF
-
L.isPivotColumn:
Here, L.isPivotColumn[k]
is true of column k is a pivot column.
-
L.pivotRow:
Here, L.pivotRow[k]=r
if the r is the row corresponding to the k-th pivot.
Use -1 otherwise.
-
L.rank is the rank
of the matrix (or of the augmented matrix). That is,
the number of pivots.
-
L.solutionExists
should be set to true if either there is a unique
solution or if multiple solutions exist.
-
L.isUniqueSolution
should be set to true if there is a unique
solution.
-
L.x
(an array) should contain a solution, if one exists.
It should be set to
null otherwise.
If there are multiple solutions, any solution will suffice.
-
L.Ainv
should contain the inverse, if it exists (for
the case that a unique solution exists).
- For convenience, the
LinResult
object also has space to store the original matrix
and right-hand-side in
L.A
and
L.b.
Although A and b are given to you, you should
assign them to these variables. It's convenient
when you need pass along all of these between
your own methods.
- Note that
LinResult
has many other variables that you won't need for this
assignment.
- The documentation
for the class LinTool shows all the methods
that will eventually go into your class above. For this
assignment you will implement only the above methods.
- To test whether your code works, compile and execute
TestA2.java
- Important: We will use the following error convention:
If there's an error and the method needs to return an array
or an object, return null. If you need to return a number,
return -1 instead.
Submission
- Create a zip called assignment2.zip
that will contain all your code and your Part-I (in PDF).
- Upload your zip into Blackboard.