Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExamplePolynom.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExamplePolynom.cpp
27  @relates Polynom
28  @brief Example Polynom usage
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <Base/Math/Polynom.hh>
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 
39 void printPolynom(Polynom p){
40  for (unsigned int i=0; i<p.GetOrder(); i++){
41  cout << p[p.GetOrder()-i-1] << "x^" << p.GetOrder()-i-1 << " ";
42  }
43  cout<< endl;
44 }
45 
46 int main()
47 {
48 
49  //Polynom of order 3 but coefficient of x^2 is 0
50  // x + 2
51  Polynom a;
52  a.SetOrder(3);
53  a[0]=2;
54  a[1]=1;
55 
56  //Polynom of order 4
57  // 3x^3 + 2x^2 + 2x + 1
58  Polynom b;
59  b.SetOrder(4);
60  b[0]=1;
61  b[1]=2;
62  b[2]=2;
63  b[3]=3;
64 
65  //empty polynoms
66  Polynom c, d, e, f, g, h, i, j, k;
67  double z = 2.;
68  c= a+b;
69  d= b-a;
70  e= a-b;
71  f= a*b;
72  g= z*b;
73  h= b*z;
74  i+=h;
75  j-=h;
76  k=a;
77  k*=b;
78 
79  cout << "polynom a: ";printPolynom(a);
80  cout << "polynom b: ";printPolynom(b);
81  cout << "double z: " << z << endl;
82  cout << endl;
83  cout << "polynom a+b: ";printPolynom(c);
84  cout << "polynom b-a: ";printPolynom(d);
85  cout << "polynom a-b: ";printPolynom(e);
86  cout << "polynom a*b: ";printPolynom(f);
87  cout << "polynom z*b: ";printPolynom(g);
88  cout << "polynom b*z: ";printPolynom(h);
89  cout << "polynom i+=h: (should be b*z)";printPolynom(i);
90  cout << "polynom j-=h: (should be -(b*z))";printPolynom(j);
91  cout << "polynom k=a k*=b (should be a*b)";printPolynom(k);
92 }
class for Polynoms of arbitary order
Definition: Polynom.hh:46
unsigned int GetOrder() const
Definition: Polynom.hh:108
void SetOrder(unsigned int i)
sets the order of polynom to i new generated coefficients are 0
Definition: Polynom.hh:70