6 #include <gsl/gsl_errno.h> 7 #include <gsl/gsl_spline.h> 17 constexpr
size_t N = 10;
19 double xi, yi, x[
N], y[
N];
21 for (
size_t i = 0; i <
N; i++) {
22 x[i] = i + 0.5 * sin(i);
23 y[i] = i + cos(i * i);
27 gsl_interp_accel *acc = gsl_interp_accel_alloc();
28 const gsl_interp_type *t = gsl_interp_cspline;
29 gsl_spline *spline = gsl_spline_alloc(t, N);
32 gsl_spline_init(spline, x, y, N);
35 for (xi = x[0]; xi < x[9]; xi += 0.01) {
36 yi = gsl_spline_eval(spline, xi, acc);
37 std::cout << xi <<
"," << yi << std::endl;
41 gsl_spline_free(spline);
42 gsl_interp_accel_free(acc);
54 double x[4] = { 0.00, 0.10, 0.27, 0.30 };
55 double y[4] = { 0.15, 0.70, -0.10, 0.15 };
58 gsl_interp_accel *acc = gsl_interp_accel_alloc();
59 const gsl_interp_type *t = gsl_interp_cspline_periodic;
60 gsl_spline *spline = gsl_spline_alloc(t, N);
63 gsl_spline_init(spline, x, y, N);
66 for (
size_t i = 0; i <= 100; i++) {
67 double xi = (1 - i / 100.0) * x[0] + (i / 100.0) * x[N - 1];
68 double yi = gsl_spline_eval(spline, xi, acc);
69 std::cout << xi <<
"," << yi << std::endl;
73 gsl_spline_free(spline);
74 gsl_interp_accel_free(acc);
84 ofs << std::fixed << std::setprecision(2);
98 std::vector<double> xvalues, yvalues;
101 auto fn = [](
double x) {
return sin(x); };
105 for (
double x = 0; x <= 2 *
Math::PI; x += dx) {
106 xvalues.push_back(x);
107 yvalues.push_back(fn(x));
108 std::cout << x <<
"," << fn(x) << std::endl;
119 for (
double x = dx; x < 2 *
Math::PI; x += dx) {
120 data += { x, linear.
eval(x), spline.
eval(x), fn(x) };
127 ofstable << std::setprecision(4);
142 auto x = [](
double t) {
return -0.75 * pow(t, 2) + 3 * t + 1; };
144 auto xdot = [](
double t) {
return -1.5 * t + 3; };
146 auto xddot = [](
double t) {
151 std::vector<double> tvalues, xvalues;
152 for (
double t = 0; t < 4; t += 0.1) {
153 tvalues.push_back(t);
154 xvalues.push_back(x(t));
159 for (
auto t : { 0.32, 1.75, 2.22, 3.18 }) {
166 interpfn.deriv2(t) };
170 ofs << std::setprecision(4);
void ex1()
ex1 Interpolation mit gsl-Routinen
void interp2()
interp2 Beschreibung einer geradlinigen Bewegung durch Interpolation
void save(std::ostream &ofs, Format fmt) const
save Schreibe Tabelle in Datei
The Data class Eine Klasse für Zahlentabellen mit fester Anzahl von Spalten. Die Anzahl der Reihen wä...
void ex2()
ex2 Interpolation periodischer Daten
static std::ofstream get_stream(const std::string &fname)
get_output_stream Öffnen einer Ausgabedatei falls die Datei nicht geöffnet werden kann wird ein Fehle...
auto select_total_rows(size_t n, size_t start=0, bool l=true) const
get_total_rows generiere View mit eine Instanz vom Typ View bestimmter Anzahl von Spalten ...
auto get_output_stream(const char *name, Format fmt=Output::csv)
get_output_stream
static constexpr double PI
The Spline class Interpolation von diskreten Daten.
void interp1()
interp1 lineare und spline Interpolation eines diskreten Datensatzes
static const Format latex
double eval(double val)
eval Funktionswert...