[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] b-spline evaluation
From: |
Iryna Feuerstein |
Subject: |
[Help-gsl] b-spline evaluation |
Date: |
Mon, 16 Jan 2012 16:08:37 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 |
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] b-spline evaluation,
Iryna Feuerstein <=