mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Starting to use
This commit is contained in:
parent
2e6986892a
commit
6fb36c8a51
@ -42,6 +42,14 @@ namespace Grid {
|
|||||||
double lo;
|
double lo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void csv(std::ostream &out){
|
||||||
|
for (double x=lo; x<hi; x+=(hi-lo)/1000) {
|
||||||
|
double f = approx(x);
|
||||||
|
out<< x<<" "<<f<<std::endl;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Chebyshev(double _lo,double _hi,int _order, double (* func)(double) ){
|
Chebyshev(double _lo,double _hi,int _order, double (* func)(double) ){
|
||||||
lo=_lo;
|
lo=_lo;
|
||||||
hi=_hi;
|
hi=_hi;
|
||||||
@ -52,16 +60,16 @@ namespace Grid {
|
|||||||
for(int j=0;j<order;j++){
|
for(int j=0;j<order;j++){
|
||||||
double s=0;
|
double s=0;
|
||||||
for(int k=0;k<order;k++){
|
for(int k=0;k<order;k++){
|
||||||
double y=cos(M_PI*(k+0.5)/order);
|
double y=std::cos(M_PI*(k+0.5)/order);
|
||||||
double x=0.5*(y*(hi-lo)+(hi+lo));
|
double x=0.5*(y*(hi-lo)+(hi+lo));
|
||||||
double f=func(x);
|
double f=func(x);
|
||||||
s=s+f*cos( j*M_PI*(k+0.5)/order );
|
s=s+f*std::cos( j*M_PI*(k+0.5)/order );
|
||||||
}
|
}
|
||||||
Coeffs[j] = s * 2.0/order;
|
Coeffs[j] = s * 2.0/order;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
double Evaluate(double x) // Convenience for plotting the approximation
|
double approx(double x) // Convenience for plotting the approximation
|
||||||
{
|
{
|
||||||
double Tn;
|
double Tn;
|
||||||
double Tnm;
|
double Tnm;
|
||||||
@ -91,7 +99,7 @@ namespace Grid {
|
|||||||
void PlotApprox(std::ostream &out) {
|
void PlotApprox(std::ostream &out) {
|
||||||
out<<"Polynomial approx ["<<lo<<","<<hi<<"]"<<std::endl;
|
out<<"Polynomial approx ["<<lo<<","<<hi<<"]"<<std::endl;
|
||||||
for(double x=lo;x<hi;x+=(hi-lo)/50.0){
|
for(double x=lo;x<hi;x+=(hi-lo)/50.0){
|
||||||
out <<x<<"\t"<<Evaluate(x)<<std::endl;
|
out <<x<<"\t"<<approx(x)<<std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user