summaryrefslogtreecommitdiff
path: root/src/c/matrixOperations/hilb/testHilbert.c
diff options
context:
space:
mode:
authorSiddhesh Wani2015-05-25 14:46:31 +0530
committerSiddhesh Wani2015-05-25 14:46:31 +0530
commitdb464f35f5a10b58d9ed1085e0b462689adee583 (patch)
treede5cdbc71a54765d9fec33414630ae2c8904c9b8 /src/c/matrixOperations/hilb/testHilbert.c
downloadScilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.gz
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.bz2
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.zip
Original Version
Diffstat (limited to 'src/c/matrixOperations/hilb/testHilbert.c')
-rw-r--r--src/c/matrixOperations/hilb/testHilbert.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/c/matrixOperations/hilb/testHilbert.c b/src/c/matrixOperations/hilb/testHilbert.c
new file mode 100644
index 0000000..2dab1a0
--- /dev/null
+++ b/src/c/matrixOperations/hilb/testHilbert.c
@@ -0,0 +1,112 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008-2008 - INRIA - Allan SIMON
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+#include "hilb.h"
+
+#define SIZE 6
+
+static void shilbaTest ( void ){
+
+ int i = 0 ;
+ int j = 0 ;
+
+
+ float Result[] =
+ {36.0f,-630.0f,3360.0f,-7560.0f,7560.0f,-2772.0f,
+-630.0f,14700.0f,-88200.0f,211680.0f,-220500.0f,83160.0f,
+3360.0f,-88200.0f,564480.0f,-1411200.0f,1512000.0f,-582120.0f,
+-7560.0f,211680.0f,-1411200.0f,3628800.0f,-3969000.0f,1552320.0f,
+7560.0f,-220500.0f,1512000.0f,-3969000.0f,4410000.0f,-1746360.0f,
+-2772.0f,83160.0f,-582120.0f,1552320.0f,-1746360.0f,698544.0f};
+
+
+
+ float out[SIZE*SIZE] ;
+ shilba ( out , SIZE ) ;
+
+ for (i = 0 ; i < SIZE ; i++)
+ {
+ printf ("\n\t" ) ;
+ for ( j = 0 ; j < SIZE; j++)
+ printf ("%e\t" , out[i + j*SIZE] );
+
+ }
+
+ for ( i = 0 ; i < SIZE*SIZE ; i++ )
+ {
+ assert ( fabs ( out[i] - Result[i] ) / fabs( out[i]) < 1e-06 ) ;
+ }
+
+ printf ("\n\n" ) ;
+}
+
+static void dhilbaTest ( void ){
+
+ int i = 0 ;
+ int j = 0 ;
+
+ double Result[] =
+{36,-630,3360,-7560,7560,-2772,
+-630,14700,-88200,211680,-220500,83160,
+3360,-88200,564480,-1411200,1512000,-582120,
+-7560,211680,-1411200,3628800,-3969000,1552320,
+7560,-220500,1512000,-3969000,4410000,-1746360,
+-2772,83160,-582120,1552320,-1746360,698544}
+;
+
+
+ double out[SIZE*SIZE] ;
+
+ dhilba ( out , SIZE ) ;
+
+ for (i = 0 ; i < SIZE ; i++)
+ {
+ printf ("\n\t" ) ;
+ for ( j = 0 ; j < SIZE; j++)
+ printf ("%e\t" , out[i + j*SIZE] );
+
+ }
+
+
+ for ( i = 0 ; i < SIZE*SIZE ; i++ )
+ {
+ assert ( fabs ( out[i] - Result[i] ) / fabs( out[i]) < 1e-16 ) ;
+ }
+
+ printf ("\n\n" ) ;
+}
+
+
+
+static int testHilbert(void) {
+
+ printf("\n>>>>Hilbert's Matrix Tests\n");
+
+ printf("\n\t>>> Float Test\n");
+ shilbaTest();
+
+ printf("\n\t>>> Double Test\n");
+ dhilbaTest();
+
+ return 0;
+}
+
+
+
+int main(void) {
+ assert(testHilbert() == 0);
+ return 0;
+}