00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <LegendreBasis.hpp>
00021 #include <iostream>
00022 #include <Types.hpp>
00023 #include <vector>
00024
00025 LegendreBasis::
00026 LegendreBasis(const LegendreBasis& legendreBasis)
00027 : __degree(legendreBasis.__degree)
00028 {
00029 ;
00030 }
00031
00032
00033 LegendreBasis::
00034 LegendreBasis(const size_t& degree)
00035 : __degree(degree)
00036 {
00037 ;
00038 }
00039
00040 LegendreBasis::
00041 ~LegendreBasis()
00042 {
00043 ;
00044 }
00045
00046 void LegendreBasis::
00047 getValues(const real_t& x,
00048 Vector<real_t>& values) const
00049 {
00050 values[0] = 1;
00051 if (__degree == 0) return ;
00052
00053 values[1] = x;
00054
00055 for (size_t n=1; n<values.size()-1; ++n) {
00056 values[n+1] = ((2*n+1)*x*values[n]-n*values[n-1]) / (n+1);
00057 }
00058 }
00059
00060 void LegendreBasis::
00061 getDerivativeValues(const real_t& x,
00062 Vector<real_t>& derivateValues) const
00063 {
00064 derivateValues[0]= 0;
00065 if (__degree == 0) return ;
00066
00067 derivateValues[1]= 1;
00068 if (__degree == 1) return ;
00069
00070 Vector<real_t> values(derivateValues.size()-1);
00071 getValues(x,values);
00072
00073 for (size_t n=1; n<derivateValues.size()-1; ++n) {
00074 derivateValues[n+1]
00075 = ((2*n+1)*(x*derivateValues[n]+values[n])
00076 - n*derivateValues[n-1])
00077 / (n+1);
00078 }
00079 }
00080
00081 void LegendreBasis::
00082 getSecondDerivativeValues(const real_t& x,
00083 Vector<real_t>& secondDerivateValues) const
00084 {
00085 secondDerivateValues[0]= 0;
00086 if (__degree == 0) return ;
00087
00088 secondDerivateValues[1]= 0;
00089 if (__degree == 1) return ;
00090
00091 Vector<real_t> values(secondDerivateValues.size()-1);
00092 getDerivativeValues(x,values);
00093
00094 for (size_t n=1; n<secondDerivateValues.size()-1; ++n) {
00095 secondDerivateValues[n+1]
00096 = ((2*n+1)*(x*secondDerivateValues[n] + 2*values[n])
00097 - n* secondDerivateValues[n-1])
00098 /(n+1);
00099 }
00100 }
00101
00102 real_t LegendreBasis::
00103 getValue(const real_t& x,
00104 const size_t& i) const
00105 {
00106 Vector<real_t> values(__degree+1);
00107 this->getValues(x,values);
00108 return values[i];
00109 }
00110
00111 real_t LegendreBasis::
00112 getDerivativeValue(const real_t& x,
00113 const size_t& i) const
00114 {
00115 Vector<real_t> derivateValues(__degree+1);
00116 this->getDerivativeValues(x, derivateValues);
00117
00118 return derivateValues[i];
00119 }
00120
00121 real_t LegendreBasis::
00122 getSecondDerivativeValue(const real_t& x,
00123 const size_t& i) const
00124 {
00125 Vector<real_t> secondDerivateValues(__degree+1);
00126 this->getSecondDerivativeValues(x, secondDerivateValues);
00127
00128 return secondDerivateValues[i];
00129 }