Skip to content

Instantly share code, notes, and snippets.

@mskashi
Created February 24, 2016 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskashi/8252f97bdb1742322b04 to your computer and use it in GitHub Desktop.
Save mskashi/8252f97bdb1742322b04 to your computer and use it in GitHub Desktop.
#include <kv/kraw-approx.hpp>
#include <kv/defint.hpp>
namespace ub = boost::numeric::ublas;
typedef kv::interval<double> itv;
struct Func {
template <class T> ub::vector<T> operator() (const ub::vector<T>& x) {
static T p = kv::constants<T>::pi();
static T c1 = kv::constants<T>::str("3.14");
ub::vector<T> y(1);
y(0) = p * x(0) * sin(11 / x(0)) - 11 * c1;
return y;
}
};
template <class TT>
struct Func2 {
TT r;
Func2(TT r) : r(r) {}
template <class T> T operator() (const T& x) {
static T p = kv::constants<T>::pi();
return 2 * p * r * sin(x / r);
}
};
int main()
{
ub::vector<itv> ix;
ub::vector<itv::base_type> x;
bool b;
std::cout.precision(12);
x.resize(1);
ix.resize(1);
x(0) = 200.;
b = kv::krawczyk_approx(Func(), x, ix, 5, false);
if (b == false) {
std::cout << "fail\n";
return 1;
} else {
std::cout << ix(0) << "\n";
}
std::cout << kv::defint_autostep(Func2<itv>(ix(0)), itv(0), itv(11), 12) << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment