Commit 7a5d7f6c by Ned Coltman Committed by Timo Koch

### [math][linspace] move linspace to math.hh

parent 2fe262e9
 ... ... @@ -562,6 +562,26 @@ struct LinearTable } // end namespace InterpolationPolicy /*! * \ingroup Common * \brief Generates linearly spaced vectors * * \param begin The first value in the vector * \param end The last value in the vector * \param samples The size of the vector */ template std::vector linspace(const Scalar begin, const Scalar end, std::size_t samples) { using std::max; samples = max(std::size_t{2}, samples); // only makes sense for 2 or more samples const Scalar delta = (end-begin)/static_cast(samples-1); std::vector vec(samples); for (std::size_t i = 0; i < samples; ++i) vec[i] = begin + i*delta; return vec; } /*! * \ingroup Common ... ...
 ... ... @@ -29,18 +29,10 @@ #include #include #include #include #include std::vector linspace(const double begin, const double end, const double samples) { const double delta = (end-begin)/static_cast(samples-1); std::vector vec(samples); for (int i = 0; i < samples; ++i) vec[i] = begin + i*delta; return vec; } template std::vector eval(const Function& f, const std::vector& x) { ... ... @@ -58,12 +50,12 @@ int main(int argc, char** argv) const auto df = [](double x){ return -2.0*x/(( 1.0 + x*x )*( 1.0 + x*x )); }; // create some test samples const auto testPoints = linspace(-4.0, 4.0, 1000); const auto testPoints = Dumux::linspace(-4.0, 4.0, 1000); const auto ref = eval(f, testPoints); const auto refDeriv = eval(df, testPoints); // create the spline sample points const auto samplePoints = linspace(-4.0, 4.0, 15); const auto samplePoints = Dumux::linspace(-4.0, 4.0, 15); const auto y = eval(f, samplePoints); // create the spline ... ... @@ -86,7 +78,7 @@ int main(int argc, char** argv) DUNE_THROW(Dune::Exception, "Maximum error in spline interpolation too large!"); // plot with Gnuplot (plot a bit more so we can see the linear extension) const auto plotPoints = linspace(-8.0, 8.0, 1000); const auto plotPoints = Dumux::linspace(-8.0, 8.0, 1000); const auto refPlot = eval(f, plotPoints); const auto refDerivPlot = eval(df, plotPoints); const auto resultPlot = eval([&](const double x) { return spline.eval(x); }, plotPoints); ... ...
 ... ... @@ -29,18 +29,10 @@ #include #include #include #include #include std::vector linspace(const double begin, const double end, const double samples) { const double delta = (end-begin)/static_cast(samples-1); std::vector vec(samples); for (int i = 0; i < samples; ++i) vec[i] = begin + i*delta; return vec; } template std::vector eval(const Function& f, const std::vector& x) { ... ... @@ -58,12 +50,12 @@ int main(int argc, char** argv) const auto df = [](double x){ return 3*x*x; }; // create some test samples const auto testPoints = linspace(0.0, 4.0, 1000); const auto testPoints = Dumux::linspace(0.0, 4.0, 1000); const auto ref = eval(f, testPoints); const auto refDeriv = eval(df, testPoints); // create the spline sample points const auto samplePoints = linspace(0.0, 5.0, 10); const auto samplePoints = Dumux::linspace(0.0, 5.0, 10); const auto y = eval(f, samplePoints); // create the spline ... ... @@ -88,7 +80,7 @@ int main(int argc, char** argv) DUNE_THROW(Dune::Exception, "Maximum error in spline interpolation too large!"); // plot with Gnuplot (plot a bit more so we can see the linear extension) const auto plotPoints = linspace(-1.0, 5.0, 1000); const auto plotPoints = Dumux::linspace(-1.0, 5.0, 1000); const auto refPlot = eval(f, plotPoints); const auto refDerivPlot = eval(df, plotPoints); const auto resultPlot = eval([&](const double x) { return spline.eval(x); }, plotPoints); ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!