Skip to main content
RISC
  • Home
  • More
English ‎(en)‎
Deutsch ‎(de)‎ English ‎(en)‎
You are currently using guest access
Log in
RISC
Home
Expand all Collapse all
  1. PractSoftTech15
  2. Exercises
  3. Exercise 1 (Strings, Arrays, Classes, Methods)

Exercise 1 (Strings, Arrays, Classes, Methods)

Completion requirements
Opened: Wednesday, 11 March 2015, 12:00 AM
Due: Wednesday, 18 March 2015, 11:55 PM


  • Let \( f\colon \mathbb{R}^n\rightarrow \mathbb{R}^m \) be a linear map.
  • Compute the transformation matrix \( M \) for arbitrary \( f \) such that \( f(\vec{x})=M\vec{x} \) for all \( \vec{x}\in\mathbb{R}^n \).

Assumptions

  • We approximate \( x\in \mathbb{R} \) by float values and vectors \( \vec{x} \) by float arrays.
  • A linear function \( f \) is represented by a class named LinearFnc.
  • Assume that LinearFnc contains a method applyTo which maps a float array of length \( n \) to a float array of length \( m \).
public class LinearFnc {<br>    ...<br>    public float[] applyTo(float[] domVec) {<br>        float[] ranVec = new float[m];<br>        ...<br>        return ranVec;<br>    }
}

Implementation

  • Write an arbitrary test class which contains the entry point public static void main(...) {...}. This class is for testing purpose only and must not be submitted.
  • Write a class Matrix which represents \( M \) in a separate file Matrix.java. This class should not contain an entry point public static void main(...) {...}.
  • The constructor of Matrix fixes the dimension \( m\times n \).
  • The class Matrix should contain three methods:
public void initMatrix(LinearFnc lfc) {...<br>public float[] applyTo(float[] domVec) {...<br>public String toString() {...<br></pre></div></div><ul><ul><li><b>initMatrix</b> computes the internal representation of \( M \), such that \( M\vec{x} \) can be computed without \( f \), for arbitrary \( \vec{x}\in\mathbb{R}^n \). The internal representation should be private.
  • applyTo computes \( M\vec{x} \), such that \( f(\vec{x})=M\vec{x} \) for all \( \vec{x}\in\mathbb{R}^n \).
  • toString returns a String representation of the transformation matrix \( M \).
  • Submit only the file Matrix.java.
  • Hint

    Implement a class LinearFnc which represents some fixed \( f \) and compare the result of Matrix.applyTo with the result of LinearFnc.applyTo for some test cases.

    You are currently using guest access (Log in)
    Data retention summary
    Get the mobile app
    Powered by Moodle