Hello,
I've tried to construct b-splines and evaluate them on the uniform
knots. I become always the same error on the margins of the interval,
over which the b-splines where constructed.
Here my code:
#include <iostream>
#include <gsl/gsl_bspline.h>
int main()
{
// allocate workspace for 5 cubic b-spline functions
gsl_bspline_workspace * w = gsl_bspline_alloc(4, 5);
// construct five uniform knots {0, 1, 2, 3, 4}
gsl_bspline_knots_uniform(0, 4, w);
// allocate vector to save the b-spline values
// the size of the vector is in this case 7
gsl_vector * values = gsl_vector_alloc(gsl_bspline_ncoeffs(w));
// evaluate all of the created b-splines at the point x = 0
gsl_bspline_eval(0, values, w);
std::cout << "x = 0, values: ";
for (std::size_t i = 0; i < values->size; i++)
std::cout << gsl_vector_get(values, i) << " ";
std::cout << std::endl;
// evaluate all of the created b-splines at the point x = 1
gsl_bspline_eval(1, values, w);
std::cout << "x = 1, values: ";
for (std::size_t i = 0; i < values->size; i++)
std::cout << gsl_vector_get(values, i) << " ";
std::cout << std::endl;
// evaluate all of the created b-splines at the point x = 2
gsl_bspline_eval(2, values, w);
std::cout << "x = 2, values: ";
for (std::size_t i = 0; i < values->size; i++)
std::cout << gsl_vector_get(values, i) << " ";
std::cout << std::endl;
// evaluate all of the created b-splines at the point x = 3
gsl_bspline_eval(3, values, w);
std::cout << "x = 3, values: ";
for (std::size_t i = 0; i < values->size; i++)
std::cout << gsl_vector_get(values, i) << " ";
std::cout << std::endl;
// evaluate all of the created b-splines at the point x = 4
gsl_bspline_eval(4, values, w);
std::cout << "x = 4, values: ";
for (std::size_t i = 0; i < values->size; i++)
std::cout << gsl_vector_get(values, i) << " ";
std::cout << std::endl;
}
The output of the program should be:
x = 0, values: 0,166667 0,666667 0,166667 0 0 0 0
x = 1, values: 0 0,166667 0,666667 0,166667 0 0 0
x = 2, values: 0 0 0,166667 0,666667 0,166667 0 0
x = 3, values: 0 0 0 0,166667 0,666667 0,166667 0
x = 4, values: 0 0 0 0 0,166667 0,666667 0,166667
But I get:
x = 0, values: 1 0 0 0
0 0 0
x = 1, values: 0 0,25 0,583333 0,166667 0 0 0
x = 2, values: 0 0 0,166667 0,666667 0,166667 0 0
x = 3, values: 0 0 0 0,166667 0,583333 0,25 0
x = 4, values: 0 0 0 0
0 0 1
By construction of a workspace with more b-splines (over larger
intervals), I get the same error. The values at both first and last
knots are not calculated properly. Does anybody know the reason of this
mistake?
Best regards,
Iryna.
_______________________________________________
Help-gsl mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-gsl