本文整理汇总了C++中SymEngine::sin方法的典型用法代码示例。如果您正苦于以下问题:C++ SymEngine::sin方法的具体用法?C++ SymEngine::sin怎么用?C++ SymEngine::sin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymEngine
的用法示例。
在下文中一共展示了SymEngine::sin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
SymEngine::print_stack_on_segfault();
RCP<const Basic> e = sin(integer(1));
double r, r_exact;
for (int i = 0; i < 10000; i++)
e = pow(add(mul(add(e, pow(integer(2), integer(-3))), integer(3)),
integer(1)),
div(integer(2), integer(3)));
// Too long:
// std::cout << "Evaluating: " << *e << std::endl;
auto t1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 500; i++)
r = eval_double(*e);
auto t2 = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1)
.count()
/ 500.
<< "ms" << std::endl;
/*
In SymPy for few iterations:
In [7]: sympify("(1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1
+ 3*(1/8 + sin(1)))^(2/3)))^(2/3)))^(2/3)))^(2/3)))^(2/3)").n(20)
Out[7]: 8.0152751504518535013
// r_exact = 8.0152751504518535013;
Here is code to use SymPy for more iterations:
In [5]: e = sin(1)
In [6]: for i in range(10):
...: e = ((e+2**(-S(3)))*3 + 1)**(S(2)/3)
...:
In [7]: e.n(20)
Out[7]: 9.6473976427977306146
But unfortunately SymPy can't do more than perhaps 10 or 20 iterations,
while
we need to test ~10000. However, the numbers seem to converge to 9.85647...
*/
r_exact = 9.8564741713701043569;
std::cout << "r (double) = " << r << std::endl;
std::cout << "r (exact) = " << r_exact << std::endl;
std::cout << "error = " << std::abs(r - r_exact) << std::endl;
return 0;
}
示例2: S2
double S2()
{
RCP<const Basic> x = symbol("x");
RCP<const Basic> y = symbol("y");
RCP<const Basic> z = symbol("z");
RCP<const Basic> e;
RCP<const Basic> f;
e = pow(add(pow(x, sin(x)), add(pow(y, cos(y)), pow(z, add(x, y)))), integer(100));
auto t1 = std::chrono::high_resolution_clock::now();
f = expand(e);
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1000000000.0;
}
示例3: a
using SymEngine::E;
using SymEngine::EulerGamma;
using SymEngine::loggamma;
using SymEngine::gamma;
using SymEngine::vec_basic;
using SymEngine::rational_class;
using SymEngine::max;
using SymEngine::min;
using SymEngine::min;
using SymEngine::NotImplementedError;
using SymEngine::SymEngineException;
TEST_CASE("eval_double: eval_double", "[eval_double]")
{
RCP<const Basic> r1, r2, r3, r4, r5;
r1 = sin(integer(1));
r2 = sin(div(integer(1), integer(2)));
r3 = div(one, integer(5));
r4 = integer(5);
#ifdef HAVE_SYMENGINE_MPFR
SymEngine::mpfr_class a(100);
SymEngine::eval_mpfr(a.get_mpfr_t(), *r1, MPFR_RNDN);
r5 = SymEngine::real_mpfr(std::move(a));
#else
r5 = SymEngine::real_double(SymEngine::eval_double(*r1));
#endif
std::vector<std::pair<RCP<const Basic>, double>> vec = {
{r1, 0.841470984808},
{r2, 0.479425538604},
示例4: REQUIRE
REQUIRE(unified_eq(gens, rgens));
// 2**(2*x + 1) -> (2**x)
basic = pow(i2, add(mul(i2, x), one));
gens = _find_gens_poly(basic);
rgens = {{twopx, one}};
REQUIRE(unified_eq(gens, rgens));
// 2**(x**(x+1))-> (2**(x**(x+1)))
basic = pow(i2, pow(x, add(x, one)));
gens = _find_gens_poly(basic);
rgens = {{basic, one}};
REQUIRE(unified_eq(gens, rgens));
// sin(x)*sin(y) + sin(x)**2 + sin(y) -> (sin(x), sin(y))
basic = add(mul(sin(x), sin(y)), add(pow(sin(x), i2), sin(y)));
gens = _find_gens_poly(basic);
rgens = {{sin(x), one}, {sin(y), one}};
REQUIRE(unified_eq(gens, rgens));
// 2**x + 2**(x+y) -> (2**x, 2**y)
basic = add(twopx, pow(i2, add(x, y)));
gens = _find_gens_poly(basic);
rgens = {{pow(i2, y), one}, {twopx, one}};
REQUIRE(unified_eq(gens, rgens));
// x**x + x**(x/2) + x**(x/3) -> (x**(x/6))
basic = add(pow(x, x), add(pow(x, div(x, i2)), pow(x, div(x, i3))));
gens = _find_gens_poly(basic);
rgens = {{pow(x, x), rcp_static_cast<const Number>(div(one, i6))}};
REQUIRE(unified_eq(gens, rgens));
示例5: sin
using SymEngine::cosh;
using SymEngine::tanh;
using SymEngine::coth;
using SymEngine::asinh;
using SymEngine::acosh;
using SymEngine::atanh;
using SymEngine::acoth;
using SymEngine::log;
using SymEngine::pi;
using SymEngine::E;
using SymEngine::vec_basic;
TEST_CASE("eval_double: eval_double", "[eval_double]")
{
RCP<const Basic> r1, r2, r3, r4;
r1 = sin(integer(1));
r2 = sin(div(integer(1), integer(2)));
r3 = div(one, integer(5));
r4 = integer(5);
std::vector<std::pair<RCP<const Basic>, double>> vec = {
{ r1, 0.841470984808 },
{ r2, 0.479425538604 },
{ add(r1, r2), 1.320896523412 },
{ mul(r1, r2), 0.403422680111 },
{ pow(r1, r2), 0.920580670898 },
{ tan(pow(r1, r2)), 1.314847038576 },
{ add(sin(r3), add(cos(r4), add(tan(r3), add(sec(integer(6)), add(csc(r4), cot(r4)))))), 0.387875350057 },
{ add(asin(r3), add(acos(r3), add(atan(r3), add(asec(integer(6)), add(acsc(r4), acot(r4)))))), 3.570293614860 },
{ add(sinh(one), add(cosh(one), add(tanh(one), coth(one)))), 4.792911269914 },
{ add(asinh(r4), add(acosh(r4), add(atanh(r3), acoth(r4)))), 5.010335118942 },