00001 #include <cxxtls/cubic_spline.h>
00002 #include <iostream>
00003 #include <cxxtls/ascii_chart.h>
00004 #include <vector>
00005 #include <math.h>
00006
00007 using namespace std;
00008 using namespace cxxtls;
00009
00010 int main()
00011 {
00012 cout << "Cubic spline test begins" << endl;
00013
00014 {
00015
00016 static pair<double, double> tmp[] =
00017 {
00018 pair<double,double>(10,00),
00019 pair<double,double>(20,10),
00020 pair<double,double>(30,00),
00021 pair<double,double>(40,-10),
00022 pair<double,double>(50,00)
00023 };
00024
00025 int count = sizeof(tmp)/sizeof(tmp[0]);
00026
00027 cubic_spline s(tmp, tmp+count);
00028
00029 ascii_chart chart(70,40);
00030
00031 vector< pair<double,double> > points(70);
00032
00033 s.evaluate(0,1, points.begin(), points.end());
00034
00035 chart.plot(points);
00036
00037 chart.title_ = "Sinusoidal data set";
00038
00039 cout << chart;
00040
00041 }
00042
00043
00044 {
00045 static pair<double, double> tmp[] =
00046 {
00047 pair<double,double>(0,01),
00048 pair<double,double>(1,02),
00049 pair<double,double>(2,04),
00050 pair<double,double>(3, 8),
00051 pair<double,double>(4,16),
00052 pair<double,double>(5,32),
00053 };
00054
00055 int count = sizeof(tmp)/sizeof(tmp[0]);
00056
00057 cubic_spline s(tmp, tmp+count);
00058
00059 ascii_chart chart(70,40);
00060
00061 vector< pair<double,double> > points(6);
00062
00063 s.evaluate(0,1, points.begin(), points.end());
00064
00065 chart.plot(points);
00066
00067 chart.title_ = "2 ^^ X";
00068
00069 cout << chart;
00070
00071 }
00072
00073 {
00074 vector< pair<double, double> > tmp;
00075
00076 int i;
00077
00078 for(i=1; i < 10; ++i)
00079 {
00080 double d = double(i);
00081
00082 double l = log(d);
00083
00084 tmp.push_back( pair<double,double>(d,l) );
00085
00086 }
00087
00088 cubic_spline s(tmp.begin(), tmp.end());
00089
00090 ascii_chart chart(70,40);
00091
00092 vector< pair<double,double> > points(50);
00093
00094 s.evaluate(0,0.2, points.begin(), points.end());
00095
00096 chart.plot(points);
00097
00098 chart.title_ = "log(x)";
00099
00100 cout << chart;
00101
00102 }
00103
00104
00105 }