home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
RLaB 1.18c
/
test
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Text File
|
1995-02-25
|
70.9 KB
|
1,445 lines
|
[
TEXT/ttxt
]
//
// Test Suite for RLaB.
// This test suite is supposed to test as much as possible, and still
// be runable on most platforms. This means we cannot do graphics or
// other platform specific stuff like piping. However, that is OK,
// since we are mostly interested in assuring the builder that RLaB
// will produce correct numerical answers.
// We use randsvd, which in turn uses RLaB's random number
// generator. We try to be carefull and seed the random number
// generator so that each user will get similar results (or at least
// similar inputs to the tests).
// Test the other style comments
1 + 2; // A simple statement with trailing comment.
# Optional RLaB comment style.
1 + 2; # A simple statement with trailing comment.
% Optional Matlab comment style.
1 + 2; % A simple statement with trailing comment.
srand (SEED = 10); // Seems to produce reasonable results
rand("default");
tic(); // Start timing the tests...
//
// Test Parameters and some functions we will need later
//
pi = 4.0*atan(1.0);
X = 3; // should be 3 (heuristic).
//
// Compute machine epsilon
//
epsilon = function()
{
eps = 1.0;
while((eps + 1.0) != 1.0)
{
eps = eps/2.0;
}
return 2*eps;
};
eps = epsilon();
eye = function( m , n )
{
if (!exist (n))
{
if(m.n != 2) { error("only 2-el MATRIX allowed as eye() arg"); }
new = zeros (m[1], m[2]);
N = min ([m[1], m[2]]);
else
if (class (m) == "string" || class (n) == "string") {
error ("eye(), string arguments not allowed");
}
if (max (size (m)) == 1 && max (size (n)) == 1)
{
new = zeros (m[1], n[1]);
N = min ([m[1], n[1]]);
else
error ("matrix arguments to eye() must be 1x1");
}
}
for(i in 1:N)
{
new[i;i] = 1.0;
}
return new;
};
symm = function( A )
{
return (A + A')./2;
};
//-------------------------------------------------------------------//
// Synopsis: Pascal matrix.
// Syntax: P = pascal ( N )
// Description:
// The Pascal matrix of order N: a symmetric positive definite
// matrix with integer entries taken from Pascal's triangle. The
// Pascal matrix is totally positive and its inverse has integer
// entries. Its eigenvalues occur in reciprocal pairs. COND(P)
// is approximately 16^N/(N*PI) for large N. PASCAL(N,1) is the
// lower triangular Cholesky factor (up to signs of columns) of
// the Pascal matrix. It is involutary (is its own
// inverse). PASCAL(N,2) is a transposed and permuted version of
// PASCAL(N,1) which is a cube root of the identity.
// References:
// R. Brawer and M. Pirovino, The linear algebra of the Pascal matrix,
// Linear Algebra and Appl., 174 (1992), pp. 13-23 (this paper
// gives a factorization of L = PASCAL(N,1) and a formula for the
// elements of L^k).
// S. Karlin, Total Positivity, Volume 1, Stanford University Press,
// 1968. (Page 137: shows i+j-1 choose j is TP (i,j=0,1,...).
// PASCAL(N) is a submatrix of this matrix.)
// M. Newman and J. Todd, The evaluation of