File: bspline_deriv.c

package info (click to toggle)
gsl 2.8%2Bdfsg-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,088 kB
  • sloc: ansic: 269,984; sh: 4,535; makefile: 902; python: 69
file content (53 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <gsl/gsl_math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_bspline.h>

int
main (void)
{
  const size_t nbreak = 6;
  const size_t spline_order = 4;
  gsl_bspline_workspace *w = gsl_bspline_alloc(spline_order, nbreak);
  const size_t p = gsl_bspline_ncontrol(w);
  const size_t n = 300;
  const double a = 0.0;
  const double b = 1.0;
  const double dx = (b - a) / (n - 1.0);
  gsl_matrix *dB = gsl_matrix_alloc(p, spline_order);
  size_t i, j, k;

  /* uniform breakpoints on [a, b] */
  gsl_bspline_init_uniform(a, b, w);

  /* output knot vector */
  gsl_vector_fprintf(stdout, w->knots, "%f");
  printf("\n\n");

  for (i = 0; i < spline_order; ++i)
    {
      for (j = 0; j < n; ++j)
        {
          double xj = j * dx;

          gsl_bspline_eval_deriv_basis(xj, i, dB, w);

          printf("%f ", xj);

          for (k = 0; k < p; ++k)
            printf("%f ", gsl_matrix_get(dB, k, i));

          printf("\n");
        }

      printf("\n\n");
    }

  gsl_matrix_free(dB);
  gsl_bspline_free(w);

  return 0;
}