1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ????-2008 - INRIA Michael Baudin
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
//define tools
function A=testmat1(a,n)
//eigen values are given by a dilation of nth roots of 1
A=diag(a*ones(1,n-1),1)+diag((1/a)*ones(1,n-1),-1)
A(1,n)=1/a;A(n,1)=a
endfunction
function r=Err(x)
r=norm(x,1)
endfunction
rand('normal')
//
// spec.tst --
// Test spec with 1 RHS and one or several LHS.
//
function r=Checktestmat1(a,n)
A=testmat1(a,n);S=spec(A);
SR=real(S);SI=imag(S);
dt=2*%i*%pi/n;Z=exp(dt*(1:n)');ZR=real(Z*((1+a*a')/a));
ZI=-imag(Z*((a*a'-1)/a));
r=max(norm(gsort(SR)-gsort(ZR)),norm(gsort(SI)-gsort(ZI)))
endfunction
function A=testmat2(a,n)
//eigen values are given by a dilation of nth roots of 1
A=testmat1(a,n);A=A+A'
endfunction
function r=Checktestmat2(a,n)
A=testmat2(a,n);S=spec(A);
SR=real(S);SI=imag(S);
dt=2*%i*%pi/n;Z=exp(dt*(1:n)');
ZR=2*real(Z*((1+a*a')/a));ZI=0*ZR;
r=max(norm(gsort(SR)-gsort(ZR)),norm(gsort(SI)-gsort(ZI)))
endfunction
// Empty matrix
A=[];
B=[];
// 1. One RHS, one LHS
S=spec(A);
if S<>[] then bugmes();quit;end
// 2. One RHS, two LHS
[al,be]=spec(A);
if al<>[] then bugmes();quit;end
if be<>[] then bugmes();quit;end
//Matrix with Inf or Nan (test de la detection d'erreur)
// 1. Real
// 1.1 Not symetric
if execstr('spec([%inf 1;2 3])','errcatch')==0 then bugmes();quit;end
if execstr('spec([1 %nan;2 3])','errcatch')==0 then bugmes();quit;end
// 1.2 Symetric
if execstr('spec([%inf 1;1 3])','errcatch')==0 then bugmes();quit;end
// 2. Complex
// 2.1 Not symetric
if execstr('spec([%inf %i;2 3])','errcatch')==0 then bugmes();quit;end
if execstr('spec([%i %i;%nan 3])','errcatch')==0 then bugmes();quit;end
// 2.2 Symetric
if execstr('spec([%inf %i;-%i 3])','errcatch')==0 then bugmes();quit;end
//Small dimension
//---------------
//Real Case
//Unsymetric, 2 LHS
if Checktestmat1(3,5)>200*%eps then bugmes();quit;end
[U,S]=spec(testmat1(3,5));
if Err(U*S/U-testmat1(3,5))>200*%eps then bugmes();quit;end
//Symmetric, 2 LHS
if Checktestmat2(3,5)>200*%eps then bugmes();quit;end
[U,S]=spec(testmat2(3,5));
if Err(U*S/U-testmat2(3,5))>200*%eps then bugmes();quit;end
//Unsymetric, 1 LHS
Scomputed = spec([2,1;3,4]);
Sexpected = [1;5];
if Err(Scomputed - Sexpected)>200*%eps then bugmes();quit;end
//Symmetric, 1 LHS
Scomputed=spec([2,1;1,2]);
Sexpected = [1;3];
if Err(Scomputed - Sexpected)>200*%eps then bugmes();quit;end
//Complex Case
//Unsymetric
if Checktestmat1(3+2*%i,5)>200*%eps then bugmes();quit;end
[U,S]=spec(testmat1(3+2*%i,5));
if Err(U*S/U-testmat1(3+2*%i,5))>200*%eps then bugmes();quit;end
//Symmetric
if Checktestmat2(3+2*%i,5)>200*%eps then bugmes();quit;end
[U,S]=spec(testmat2(3+2*%i,5));
if Err(U*S/U-testmat2(3+2*%i,5))>200*%eps then bugmes();quit;end
//Unsymetric, 1 LHS
Scomputed = spec([2*%i,1*%i;3*%i,4*%i]);
Sexpected = [%i;5*%i];
if Err(Scomputed - Sexpected)>200*%eps then bugmes();quit;end
//Symmetric, 1 LHS
Scomputed=spec([2,%i;-%i,2]);
Sexpected = [1;3];
if Err(Scomputed - Sexpected)>200*%eps then bugmes();quit;end
//Large dimension
//---------------
//Real Case
//Unsymetric
if Checktestmat1(3,50)>1000*%eps then bugmes();quit;end
[U,S]=spec(testmat1(3,50));
if Err(U*S/U-testmat1(3,50))>1000*%eps then bugmes();quit;end
//Symmetric
if Checktestmat2(3,50)>1000*%eps then bugmes();quit;end
[U,S]=spec(testmat2(3,50));
if Err(U*S/U-testmat2(3,50))>1000*%eps then bugmes();quit;end
//Complex Case
//Unsymetric
if Checktestmat1(3+2*%i,50)>1000*%eps then bugmes();quit;end
[U,S]=spec(testmat1(3+2*%i,50));
if Err(U*S/U-testmat1(3+2*%i,50))>1000*%eps then bugmes();quit;end
//Symmetric
if Checktestmat2(3+2*%i,50)>1000*%eps then bugmes();quit;end
[U,S]=spec(testmat2(3+2*%i,50));
if Err(U*S/U-testmat2(3+2*%i,50))>10000*%eps then bugmes();quit;end
|