\(
\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 1
Part I: Pen-and-paper
- In this problem, you will get a little practice with "crank it
out" proofs and in doing so, refresh what you know about complex
numbers. Recall
that the conjugate of a complex number \(z = a+ib\) is the
complex number \(\overline{z} = a-ib\). Now
suppose \(z_1\) and \(z_2\) are complex numbers. Show that:
- \(\overline{z_1 + z_2} = \overline{z_1} + \overline{z_2}\)
- \(\overline{z_1 - z_2} = \overline{z_1} - \overline{z_2}\)
- \(\overline{(z_1 z_2)} = \overline{z_1} \;\; \overline{z_2}\)
- For vectors \({\bf u}\) and \({\bf v}\), provide
a geometric proof that
\(|{\bf u} + {\bf v}| \leq |{\bf u}| + |{\bf v}|\).
-
What is the implication for complex numbers? Can the same idea
lead to the conclusion that \(|z_1 + z_2| \leq |z_1| + |z_2|\)?
- For real vectors \({\bf u}\) and \({\bf v}\),
we know that
\({\bf u} \cdot {\bf v} = |{\bf u}| |{\bf v}| \cos\theta\),
where \(\theta\) is the angle between them. From this,
what can you conclude about the size relationship
between
\(|{\bf u} \cdot {\bf v}|\) and \(|{\bf u}| |{\bf v}|\)?
Is one always less than the other?
Part II: Programming
As part of this course, you will learn core ideas in linear algebra
by seeing them in code. Most of this will occur through building
your own library of linear algebra code, written in a single
Java class.
- You already have lintool.jar in your CLASSPATH. If
not, please follow these instructions
- Create a directory called assignment1 for this
assignment.
- The first step is to implement a class for complex numbers.
Use the following naming convention: if your username is
alice, call the class AliceComplex.
- Your implementation will need to extend the
class ComplexNumber defined in the
javadoc for ComplexNumber.
Thus, your extension will look like:
import edu.gwu.lintool.*;
public class AliceComplex extends ComplexNumber {
// Do NOT define re, im: these are inherited
// ... all the various methods in here, such as:
// add(), magnitude() etc ...
}
- The particular methods you need to implement for complex numbers are:
import edu.gwu.lintool.*;
public class AliceComplex extends ComplexNumber {
public abstract double magnitude ();
public abstract double angle ();
public abstract ComplexNumber add (ComplexNumber c);
public abstract ComplexNumber sub (ComplexNumber c);
public abstract ComplexNumber mult (ComplexNumber c);
public abstract ComplexNumber mult (double a);
public abstract ComplexNumber pow (int n);
public abstract ComplexNumber conjugate ();
}
- Please DO NOT change the method signatures or parameters.
Because of this you will need to cast to your own class in some methods.
For example:
public ComplexNumber add (ComplexNumber b)
{
AliceComplex c = (AliceComplex) b;
return new AliceComplex (re + c.re, im + c.im);
// This works because AliceComplex is an extension of ComplexNumber.
}
- Notice that our class AliceComplex above used
a two-parameter constructor. You will need both a two-parameter
constructor AND a no-parameter constructor.
- Your class will provide implementations for only the abstract
methods. The data fields (real and imaginary parts, the angle)
are already defined. Do NOT put these in your code. But store
values that you need to in those fields (re, im, angle).
- Make sure your angle is between \(0\) and \(2\pi\).
- To test whether your code works, compile and execute
TestA1.java, after un-commenting
the test for complex numbers.
- Note: Lintool will not test all your methods. You are
encouraged to write your own tests.
- Next, after this, implement code for vector and matrix
operations. Use the following convention to name your tool.
If your username is alice, your tool will be called
AliceLinTool.
- Your class should extend LinToolEmpty as follows:
import edu.gwu.lintool.*;
public class AliceLinTool extends LinToolEmpty {
// YOUR CODE WILL GO IN HERE
}
- Within the class, you will implement methods that will
override the default implementations (which do nothing)
that are inherited from LinToolEmpty. The class
LinToolEmpty is intended to simplify coding so
you don't have to have a whole bunch of default implementations.
- 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 some of those methods,
the methods for complex numbers and for basic matrix-vector operations.
- For this assignment, you will implement the following methods:
// Vector operations:
public abstract double[] add (double[] u, double[] v);
public abstract double norm (double[] v);
public abstract double dotProduct (double[] u, double[] v);
public abstract double[] scalarProduct (double alpha, double[] v);
public abstract boolean approxEquals (double[] u, double[] v, double errorTolerance);
public abstract double cosine (double[] u, double[] v);
// Matrix operations:
public abstract double[][] add (double[][] A, double[][] B);
public abstract double[][] scalarProduct (double alpha, double[][] A);
public abstract double[][] mult (double[][] A, double[][] B);
public abstract double[] matrixVectorMult (double[][] A, double[] v);
public abstract double[] vectorMatrixMult (double[] v, double[][] A);
// In vectorLeftMult(), u is a column, v is a row:
public abstract double[][] vectorLeftMult (double[] u, double[] v);
public abstract double[][] transpose (double[][] A);
public abstract double frobeniusNorm (double[][] A); // Look this up.
// Sum of squared-differences less than tolerance:
public abstract boolean approxEquals (double[][] A, double[][] B, double errorTolerance);
public abstract double[] getColumnAsVector (double[][] A, int col);
public abstract double[] getRowAsVector (double[][] A, int row);
- Almost all of these are straightforward. However, you need to
be careful to perform some checking to see if lengths are
compatible and so on.
- Some of the methods above will need some on-your-own reading,
such as left multiplication of a matrix by a row vector,
and the Frobenius norm of a matrix.
- 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 assignment1.zip
that will contain all your code and pdf of your pen-and-paper problems
(name the pdf assignment1.pdf).
- Upload your zip into Blackboard.