examples/test_poly/test_poly.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*------------------------------------------------------------*/
00021 /** @file test_poly.c Test program for vectors types          */
00022 /*------------------------------------------------------------*/
00023 
00024 #include <it/io.h>
00025 #include <it/vec.h>
00026 #include <it/poly.h>
00027 
00028 int main ()
00029 {
00030   vec  P0 = vec_new_string ("1 6 1"); /* 1 + 6X + X^2 */
00031   vec  P1 = vec_new_string ("4 4"); /* 4 + 4X */
00032   vec  R;
00033 
00034   pvec V;
00035   pmat M;
00036 
00037   /* arithmetic */
00038   R = vec_clone (P0);
00039   it_printf ("%P + %P = %P\n", P0, P1, poly_add (R, P1));
00040   vec_copy (R, P0);
00041   it_printf ("%P - %P = %P\n", P0, P1, poly_sub (R, P1));
00042   vec_copy (R, P0);
00043   it_printf ("%P * %P = %P\n", P0, P1, poly_mul (R, P1));
00044   vec_copy (R, P0);
00045   it_printf ("%P / %P = %P\n", P0, P1, poly_div (R, P1));
00046   vec_copy (R, P0);
00047   it_printf ("%P %% %P = %P\n", P0, P1, poly_mod (R, P1));
00048   vec_copy (R, P0);
00049   it_printf ("gcd(%P, %P) = %P\n", P0, P1, poly_gcd (R, P1));
00050   vec_delete (R);
00051 
00052   /* evaluation */
00053   it_printf ("%P(1.5) = %f\n", P0, poly_eval (P0, 1.5));
00054 
00055   /* vector and matrices */
00056   V = pvec_new (2);
00057   M = pmat_new (2, 2);
00058   V[0] = P0;
00059   V[1] = P1;
00060   M[0][0] = P0;
00061   M[0][1] = P1;
00062   M[1][0] = P1;
00063   M[1][1] = P0;
00064   it_printf ("V = $P\n", V);
00065   it_printf ("M = #P\n", M);
00066 
00067   return 0;
00068 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau