Class MatrixF
float- Version:
- $Id: $Id
- Author:
- Raul Saavedra (rsaavedr@ai.uwf.edu)
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetDoubleValue(int r, int c) Returns the value stored at element (r,c) as a doublefloatgetValue(int r, int c) Returns the value stored at element (r,c)voidAssign zero to all elements in the matrixvoidsetDoubleValue(int r, int c, double x) Assigns double value x in matrix element (r, c).voidsetValue(int r, int c, double x) Assigns double x to matrix element at (r, c).voidsetValue(int r, int c, float x) Assigns float x to matrix element at (r, c)Methods inherited from class BasicMatrix
getName, getSize, setName, toString
-
Constructor Details
-
MatrixF
-
MatrixF
Creates a matrix reading it from a filefname. The file has to be an ascii one and follow a particular format:*MATRIX* [matrix name]
[n]
[0, 0 ] [ 0, 1] ... [ 0, n-1]
[1, 0 ] [ 1, 1] ... [ 1, n-1]
:
[n-1,0] [n-1,1] ... [n-1,n-1]First token should be a word with "MATRIX" as a substring (case insens.), followed by the name of the matrix (one word). [n] is the number of rows and columns in the matrix, and [i,j] is element at position i,j in the matrix.
For example, a 3x3 identity matrix could be represented as follows:MATRIX Identity3x3
3 // # rows and columns
// Matrix elements:
1 0 0
0 1 0
0 0 1Notice there can be slash-slash (and also slash-star) style comments anywhere in the file. Numbers can be separated by any number of blank delimiters: tabs, spaces, carriage returns. In the examples above they appear in different lines for more readability of the file. The file may have less elements than the total needed to fill the matrix. If it has more elements an illegal argument exception will be generated.
- Parameters:
fname- aStringobject- Throws:
IOException- if any.
-
-
Method Details
-
setDoubleValue
public void setDoubleValue(int r, int c, double x) Assigns double value x in matrix element (r, c). Notice the presence of this method does not really force the implementing class to actually store doubles.Casts double value x to float and assigns it to element (r,c)
- Specified by:
setDoubleValuein classBasicMatrix- Parameters:
r- row indexc- column indexx- value to be assigned to element (r,c)
-
getDoubleValue
public double getDoubleValue(int r, int c) Returns the value stored at element (r,c) as a doubleReturns the value stored at element (r,c) as a double
- Specified by:
getDoubleValuein classBasicMatrix- Parameters:
r- row indexc- column index- Returns:
- the value stored at element (r,c) as a double
-
setValue
public void setValue(int r, int c, float x) Assigns float x to matrix element at (r, c)- Parameters:
r- a intc- a intx- a float
-
setValue
public void setValue(int r, int c, double x) Assigns double x to matrix element at (r, c). This method checks that the double x can be converted to a float without causing overflow.- Parameters:
r- a intc- a intx- a double
-
getValue
public float getValue(int r, int c) Returns the value stored at element (r,c)- Parameters:
r- a intc- a int- Returns:
- a float
-
setAllValuesToZero
public void setAllValuesToZero()Assign zero to all elements in the matrix- Specified by:
setAllValuesToZeroin classBasicMatrix
-