File:Cubic spline 1D interpolation.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file (SVG file, nominally 720 × 720 pixels, file size: 21 KB)

Captions

Captions

cubic spline 1D interpolation using GSL library

Summary

[edit]
Description
English: cubic spline 1D interpolation using GSL library. The program computes a cubic spline interpolation of the 10-point dataset where:
Date
Source Own work
Author Soul windsurfer

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.


c src code

[edit]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>

int
main (void)
{
  int i;
  double xi, yi, x[10], y[10];

  printf ("#m=0,S=17\n");

  for (i = 0; i < 10; i++)
    {
      x[i] = i + 0.5 * sin (i);
      y[i] = i + cos (i * i);
      printf ("%g %g\n", x[i], y[i]);
    }

  printf ("#m=1,S=0\n");

  {
    gsl_interp_accel *acc
      = gsl_interp_accel_alloc ();
    gsl_spline *spline
      = gsl_spline_alloc (gsl_interp_cspline, 10);

    gsl_spline_init (spline, x, y, 10);

    for (xi = x[0]; xi < x[9]; xi += 0.01)
      {
        yi = gsl_spline_eval (spline, xi, acc);
        printf ("%g %g\n", xi, yi);
      }
    gsl_spline_free (spline);
    gsl_interp_accel_free (acc);
  }
  return 0;
}

Compile

gcc -Wall s.c -lm -lgsl -lgslcblas

Run

./a.out > interp.dat

Create svg graphic using graph program:

graph -T svg < interp.dat > interp.svg

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current17:46, 14 November 2023Thumbnail for version as of 17:46, 14 November 2023720 × 720 (21 KB)Soul windsurfer (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata