From b22c17190d0c1df1232fc0892ccf07977b182b1c Mon Sep 17 00:00:00 2001 From: parsiad Date: Fri, 23 Jun 2017 15:55:34 -0400 Subject: [PATCH] Expanded comments in examples. --- README.md | 46 ++++++++++++++++++++++++++++++++++++---------- examples/1d.cpp | 20 +++++++++++++------- examples/2d.cpp | 20 ++++++++++++++------ 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e35874c..efec4e7 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ Let's interpolate y = sin(x) on the interval [-pi, pi] using 15 evenly-spaced da ```c++ using namespace mlinterp; -// End points +// Boundaries of the interval [-pi, pi] constexpr double b = 3.14159265358979323846, a = -b; -// Knots (xd) and values at the knots (yd) +// Subdivide the interval [-pi, pi] using 15 evenly-spaced points and +// evaluate sin(x) at each of those points constexpr int nxd = 15, nd[] = { nxd }; double xd[nxd]; double yd[nxd]; @@ -39,16 +40,27 @@ for(int n = 0; n < nxd; ++n) { yd[n] = sin(xd[n]); } -// Points at which to interpolate +// Subdivide the interval [-pi, pi] using 100 evenly-spaced points +// (these are the points at which we interpolate) constexpr int ni = 100; double xi[ni]; for(int n = 0; n < ni; ++n) { xi[n] = a + (b - a) / (ni - 1) * n; } -// Perform interpolation +// Perform the interpolation double yi[ni]; // Result is stored in this buffer -interp(nd, ni, yd, yi, xd, xi); +interp( + nd, ni, // Number of points + yd, yi, // Output axis (y) + xd, xi // Input axis (x) +); + +// Print the interpolated values +cout << scientific << setprecision(8) << showpos; +for(int n = 0; n < ni; ++n) { + cout << xi[n] << "\t" << yi[n] << endl; +} ``` ![](https://raw.githubusercontent.com/parsiad/mlinterp/master/examples/1d.png) @@ -60,10 +72,12 @@ Let's interpolate z = sin(x)cos(y) on the interval [-pi, pi] X [-pi, pi] using 1 ```c++ using namespace mlinterp; -// End points +// Boundaries of the interval [-pi, pi] constexpr double b = 3.14159265358979323846, a = -b; -// Knots (xd times yd) and values at the knots (zd) +// Discretize the set [-pi, pi] X [-pi, pi] using 15 evenly-spaced +// points along the x axis and 15 evenly-spaced points along the y axis +// and evaluate sin(x)cos(y) at each of those points constexpr int nxd = 15, nyd = 15, nd[] = { nxd, nyd }; double xd[nxd]; for(int i = 0; i < nxd; ++i) { @@ -81,7 +95,9 @@ for(int i = 0; i < nxd; ++i) { } } -// Points at which to interpolate +// Subdivide the set [-pi, pi] X [-pi, pi] using 100 evenly-spaced +// points along the x axis and 100 evenly-spaced points along the y axis +// (these are the points at which we interpolate) constexpr int m = 100, ni = m * m; double xi[ni]; double yi[ni]; @@ -93,9 +109,19 @@ for(int i = 0; i < m; ++i) { } } -// Perform interpolation +// Perform the interpolation double zi[ni]; // Result is stored in this buffer -interp(nd, ni, zd, zi, xd, xi, yd, yi); +interp( + nd, ni, // Number of points + zd, zi, // Output axis (z) + xd, xi, yd, yi // Input axes (x and y) +); + +// Print the interpolated values +cout << scientific << setprecision(8) << showpos; +for(int n = 0; n < ni; ++n) { + cout << xi[n] << "\t" << yi[n] << "\t" << zi[n] << endl; +} ``` ![](https://raw.githubusercontent.com/parsiad/mlinterp/master/examples/2d.png) diff --git a/examples/1d.cpp b/examples/1d.cpp index acdaed0..4e6335c 100644 --- a/examples/1d.cpp +++ b/examples/1d.cpp @@ -3,7 +3,7 @@ // ------ // // // // Interpolates y = sin(x) on the interval [-pi, pi] using 15 evenly-spaced // -// data points. // +// points. // //////////////////////////////////////////////////////////////////////////////// #include @@ -17,10 +17,11 @@ using namespace std; int main() { - // End points + // Boundaries of the interval [-pi, pi] constexpr double b = 3.14159265358979323846, a = -b; - // Knots (xd) and values at the knots (yd) + // Subdivide the interval [-pi, pi] using 15 evenly-spaced points and + // evaluate sin(x) at each of those points constexpr int nxd = 15, nd[] = { nxd }; double xd[nxd]; double yd[nxd]; @@ -29,18 +30,23 @@ int main() { yd[n] = sin(xd[n]); } - // Points at which to interpolate + // Subdivide the interval [-pi, pi] using 100 evenly-spaced points + // (these are the points at which we interpolate) constexpr int ni = 100; double xi[ni]; for(int n = 0; n < ni; ++n) { xi[n] = a + (b - a) / (ni - 1) * n; } - // Perform interpolation + // Perform the interpolation double yi[ni]; // Result is stored in this buffer - interp(nd, ni, yd, yi, xd, xi); + interp( + nd, ni, // Number of points + yd, yi, // Output axis (y) + xd, xi // Input axis (x) + ); - // Print interpolated values + // Print the interpolated values cout << scientific << setprecision(8) << showpos; for(int n = 0; n < ni; ++n) { cout << xi[n] << "\t" << yi[n] << endl; diff --git a/examples/2d.cpp b/examples/2d.cpp index 227b043..1f98583 100644 --- a/examples/2d.cpp +++ b/examples/2d.cpp @@ -18,10 +18,12 @@ using namespace std; int main() { - // End points + // Boundaries of the interval [-pi, pi] constexpr double b = 3.14159265358979323846, a = -b; - // Knots (xd times yd) and values at the knots (zd) + // Discretize the set [-pi, pi] X [-pi, pi] using 15 evenly-spaced + // points along the x axis and 15 evenly-spaced points along the y axis + // and evaluate sin(x)cos(y) at each of those points constexpr int nxd = 15, nyd = 15, nd[] = { nxd, nyd }; double xd[nxd]; for(int i = 0; i < nxd; ++i) { @@ -39,7 +41,9 @@ int main() { } } - // Points at which to interpolate + // Subdivide the set [-pi, pi] X [-pi, pi] using 100 evenly-spaced + // points along the x axis and 100 evenly-spaced points along the y axis + // (these are the points at which we interpolate) constexpr int m = 100, ni = m * m; double xi[ni]; double yi[ni]; @@ -51,11 +55,15 @@ int main() { } } - // Perform interpolation + // Perform the interpolation double zi[ni]; // Result is stored in this buffer - interp(nd, ni, zd, zi, xd, xi, yd, yi); + interp( + nd, ni, // Number of points + zd, zi, // Output axis (z) + xd, xi, yd, yi // Input axes (x and y) + ); - // Print interpolated values + // Print the interpolated values cout << scientific << setprecision(8) << showpos; for(int n = 0; n < ni; ++n) { cout << xi[n] << "\t" << yi[n] << "\t" << zi[n] << endl;