package Jama.test;
import Jama.*;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/** TestMatrix tests the functionality of the Jama Matrix class and associated decompositions.
<P>
Run the test from the command line using
<BLOCKQUOTE><PRE><CODE>
java Jama.test.TestMatrix
</CODE></PRE></BLOCKQUOTE>
Detailed output is provided indicating the functionality being tested
and whether the functionality is correctly implemented. Exception handling
is also tested.
<P>
The test is designed to run to completion and give a summary of any implementation errors
encountered. The final output should be:
<BLOCKQUOTE><PRE><CODE>
TestMatrix completed.
Total errors reported: n1
Total warning reported: n2
</CODE></PRE></BLOCKQUOTE>
If the test does not run to completion, this indicates that there is a
substantial problem within the implementation that was not anticipated in the test design.
The stopping point should give an indication of where the problem exists.
**/
public class TestMatrix {
public static void main (String argv[]) {
Matrix A,B,C,Z,O,I,R,S,X,SUB,M,T,SQ,DEF,SOL;
// Uncomment this to test IO in a different locale.
// Locale.setDefault(Locale.GERMAN);
int errorCount=0;
int warningCount=0;
double tmp, s;
double[] columnwise = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.};
double[] rowwise = {1.,4.,7.,10.,2.,5.,8.,11.,3.,6.,9.,12.};
double[][] avals = {{1.,4.,7.,10.},{2.,5.,8.,11.},{3.,6.,9.,12.}};
double[][] rankdef = avals;
double[][] tvals = {{1.,2.,3.},{4.,5.,6.},{7.,8.,9.},{10.,11.,12.}};
double[][] subavals = {{5.,8.,11.},{6.,9.,12.}};
double[][] rvals = {{1.,4.,7.},{2.,5.,8.,11.},{3.,6.,9.,12.}};
double[][] pvals = {{4.,1.,1.},{1.,2.,3.},{1.,3.,6.}};
double[][] ivals = {{1.,0.,0.,0.},{0.,1.,0.,0.},{0.,0.,1.,0.}};
double[][] evals =
{{0.,1.,0.,0.},{1.,0.,2.e-7,0.},{0.,-2.e-7,0.,1.},{0.,0.,1.,0.}};
double[][] square = {{166.,188.,210.},{188.,214.,240.},{210.,240.,270.}};
double[][] sqSolution = {{13.},{15.}};
double[][] condmat = {{1.,3.},{7.,9.}};
double[][] badeigs = {{0,0,0,0,0}, {0,0,0,0,1},{0,0,0,1,0},
{1,1,0,0,1},{1,0,1,0,1}};
int rows=3,cols=4;
int invalidld=5;/* should trigger bad shape for construction with val */
int raggedr=0; /* (raggedr,raggedc) should be out of bounds in ragged array */
int raggedc=4;
int validld=3; /* leading dimension of intended test Matrices */
int nonconformld=4; /* leading dimension which is valid, but nonconforming */
int ib=1,ie=2,jb=1,je=3; /* index ranges for sub Matrix */
int[] rowindexset = {1,2};
int[] badrowindexset = {1,3};
int[] columnindexset = {1,2,3};
int[] badcolumnindexset = {1,2,4};
double columnsummax = 33.;
double rowsummax = 30.;
double sumofdiagonals = 15;
double sumofsquares = 650;
/**
Constructors and constructor-like methods:
double[], int
double[][]
int, int
int, int, double
int, int, double[][]
constructWithCopy(double[][])
random(int,int)
identity(int)
**/
print("\nTesting constructors and constructor-like methods...\n");
try{
/** check that exception is thrown in packed constructor with invalid length **/
A = new Matrix(columnwise,invalidld);
errorCount = try_failure(errorCount,"Catch invalid length in packed constructor... ",
"exception not thrown for invalid input");
} catch ( IllegalArgumentException e ) {
try_success("Catch invalid length in packed constructor... ",
e.getMessage());
}
try{
/** check that exception is thrown in default constructor
if input array is 'ragged' **/
A = new Matrix(rvals);
tmp = A.get(raggedr,raggedc);
} catch ( IllegalArgumentException e ) {
try_success("Catch ragged input to default constructor... ",
e.getMessage());
} catch ( java.lang.ArrayIndexOutOfBoundsException e ) {
errorCount = try_failure(errorCount,"Catch ragged input to constructor... ",
"exception not thrown in construction...ArrayIndexOutOfBoundsException thrown later");
}
try{
/** check that exception is thrown in constructWithCopy
if input array is 'ragged' **/
A = Matrix.constructWithCopy(rvals);
tmp = A.get(raggedr,raggedc);
} catch ( IllegalArgumentException e ) {
try_success("Catch ragged input to constructWithCopy... ",e.getMessage());
} catch ( java.lang.ArrayIndexOutOfBoundsException e ) {
errorCount = try_failure(errorCount,"Catch ragged input to constructWithCopy... ","exception not thrown in construction...ArrayIndexOutOfBoundsException thrown later");
}
A = new Matrix(columnwise,validld);
B = new Matrix(avals);
tmp = B.get(0,0);
avals[0][0] = 0.0;
C = B.minus(A);
avals[0][0] = tmp;
B = Matrix.constructWithCopy(avals);
tmp = B.get(0,0);
avals[0][0] = 0.0;
if ( ( tmp - B.get(0,0) ) != 0.0 ) {
/** check that constructWithCopy behaves properly **/
errorCount = try_failure(errorCount,"constructWithCopy... ","copy not effected... data visible outside");
} else {
try_success("constructWithCopy... ","");
}
avals[0][0] = columnwise[0];
I = new Matrix(ivals);
try {
check(I,Matrix.identity(3,4));
try_success("identity... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"identity... ","identity Matrix not successfully created");
}
/**
Access Methods:
getColumnDimension()
getRowDimension()
getArray()
getArrayCopy()
getColumnPackedCopy()
getRowPackedCopy()
get(int,int)
getMatrix(int,int,int,int)
getMatrix(int,int,int[])
getMatrix(int[],int,int)
getMatrix(int[],int[])
set(int,int,double)
setMatrix(int,int,int,int,Matrix)
setMatrix(int,int,int[],Matrix)
setMatrix(int[],int,int,Matrix)
setMatrix(int[],int[],Matrix)
**/
print("\nTesting access methods...\n");
/**
Various get methods:
**/
B = new Matrix(avals);
if (B.getRowDimension() != rows) {
errorCount = try_failure(errorCount,"getRowDimension... ","");
} else {
try_success("getRowDimension... ","");
}
if (B.getColumnDimension() != cols) {
errorCount = try_failure(errorCount,"getColumnDimension... ","");
} else {
try_success("getColumnDimension... ","");
}
B = new Matrix(avals);
double[][] barray = B.getArray();
if ( barray != avals ) {
errorCount = try_failure(errorCount,"getArray... ","");
} else {
try_success("getArray... ","");
}
barray = B.getArrayCopy();
if ( barray == avals ) {
errorCount = try_failure(errorCount,"getArrayCopy... ","data not (deep) copied");
}
try {
check(barray,avals);
try_success("getArrayCopy... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"getArrayCopy... ","data not successfully (deep) copied");
}
double[] bpacked = B.getColumnPackedCopy();
try {
check(bpacked,columnwise);
try_success("getColumnPackedCopy... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"getColumnPackedCopy... ","data not successfully (deep) copied by columns");
}
bpacked = B.getRowPackedCopy();
try {
check(bpac
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA 矩阵工具包 JAMA
共40个文件
html:18个
java:9个
class:9个
5星 · 超过95%的资源 需积分: 48 68 下载量 76 浏览量
2013-04-25
19:07:53
上传
评论
收藏 109KB ZIP 举报
温馨提示
JAMA is a basic linear algebra package for Java. It provides user-level classes for constructing and manipulating real, dense matrices. It is meant to provide sufficient functionality for routine problems, packaged in a way that is natural and understandable to non-experts.
资源推荐
资源详情
资源评论
收起资源包目录
Jama-1.0.3.zip (40个子文件)
Jama
QRDecomposition.java 6KB
time
CholeskyDecomposition.java 5KB
doc
constant-values.html 5KB
index.html 1KB
overview-tree.html 7KB
allclasses-noframe.html 1KB
deprecated-list.html 5KB
help-doc.html 8KB
package-list 5B
allclasses-frame.html 1KB
resources
inherit.gif 57B
index-all.html 27KB
Jama
package-tree.html 7KB
QRDecomposition.html 15KB
LUDecomposition.html 17KB
SingularValueDecomposition.html 16KB
CholeskyDecomposition.html 14KB
package-frame.html 1KB
package-summary.html 6KB
Matrix.html 66KB
EigenvalueDecomposition.html 14KB
serialized-form.html 14KB
stylesheet.css 1KB
examples
MagicSquareExample.java 5KB
MagicSquareExample.class 4KB
EigenvalueDecomposition.java 26KB
util
Maths.class 440B
Maths.java 434B
SingularValueDecomposition.java 15KB
test
TestMatrix.java 41KB
TestMatrix.class 25KB
LUDecomposition.java 8KB
LUDecomposition.class 3KB
QRDecomposition.class 3KB
Matrix.class 12KB
CholeskyDecomposition.class 2KB
EigenvalueDecomposition.class 12KB
Matrix.java 28KB
ChangeLog 2KB
SingularValueDecomposition.class 7KB
共 40 条
- 1
alanbreeze
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页