Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExamplePolynom.cpp

Example Polynom usage

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExamplePolynom.cpp
@relates Polynom
@brief Example Polynom usage
@ingroup g_examples
@author MIP
*/
#include <Base/Math/Polynom.hh>
using namespace BIAS;
using namespace std;
void printPolynom(Polynom p){
for (unsigned int i=0; i<p.GetOrder(); i++){
cout << p[p.GetOrder()-i-1] << "x^" << p.GetOrder()-i-1 << " ";
}
cout<< endl;
}
int main()
{
//Polynom of order 3 but coefficient of x^2 is 0
// x + 2
a.SetOrder(3);
a[0]=2;
a[1]=1;
//Polynom of order 4
// 3x^3 + 2x^2 + 2x + 1
b.SetOrder(4);
b[0]=1;
b[1]=2;
b[2]=2;
b[3]=3;
//empty polynoms
Polynom c, d, e, f, g, h, i, j, k;
double z = 2.;
c= a+b;
d= b-a;
e= a-b;
f= a*b;
g= z*b;
h= b*z;
i+=h;
j-=h;
k=a;
k*=b;
cout << "polynom a: ";printPolynom(a);
cout << "polynom b: ";printPolynom(b);
cout << "double z: " << z << endl;
cout << endl;
cout << "polynom a+b: ";printPolynom(c);
cout << "polynom b-a: ";printPolynom(d);
cout << "polynom a-b: ";printPolynom(e);
cout << "polynom a*b: ";printPolynom(f);
cout << "polynom z*b: ";printPolynom(g);
cout << "polynom b*z: ";printPolynom(h);
cout << "polynom i+=h: (should be b*z)";printPolynom(i);
cout << "polynom j-=h: (should be -(b*z))";printPolynom(j);
cout << "polynom k=a k*=b (should be a*b)";printPolynom(k);
}