bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] Evaluation of B-Splines


From: Iryna Feuerstein
Subject: [Bug-gsl] Evaluation of B-Splines
Date: Mon, 16 Jan 2012 14:10:39 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1

Hallo,

I'm not really shure if it's a bug, but I cann't find other reason for the following error.

Please take a look at the following programm:

#include <iostream>
#include <gsl/gsl_bspline.h>

int main()
{
    //allocate workspace for five cubic splines
    gsl_bspline_workspace * w = gsl_bspline_alloc(4, 5);
    //construct five knots {0, 1, 2, 3, 4}
    gsl_bspline_knots_uniform(0, 4, w);
    //allocate a vector to save the b-spline values in it
    //the size of the vector is in this case 7
    gsl_vector * values = gsl_vector_alloc(gsl_bspline_ncoeffs(w));
    //evaluate the 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;

    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;

    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;

    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;

    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;
}

This programm calculates the values of the B-Splines Bi, i = -1, 0, ... , 5, at the points 0, 1, 2, 3 and 4.
The output schould be like this:
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 the programm prints the following output:
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

The same error I get, when I'm construct and evaluate b-splines over a bigger interval. The values of the first and the last two knots don't get evaluated properly. Does anybody know the reasons for such a behavior?

Best regards,
Iryna.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]