MyraMath
expr_functions_exponential


Source: tests/expression/functions.cpp

1 
2 // ========================================================================= //
3 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
4 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
5 // ========================================================================= //
6 
17 
18 // Reporting.
19 #include <tests/myratest.h>
20 
21 using namespace myra;
22 
23 #ifdef MYRAMATH_ENABLE_CPP11
24 
25 ADD_TEST("expr_functions_trig","[expression]")
26  {
27  double tol = 1.0e-12;
28  double pi = std::acos(-1.0);
29  auto E = expr({0.0,pi/6.0,pi/4.0,pi/3.0,pi/2.0});
30  REQUIRE( frobenius( sin(E) - expr({0.0,0.5,sqrt(2.0)/2.0,sqrt(3.0)/2.0,1.0}) ) < tol );
31  REQUIRE( frobenius( cos(E) - expr({1.0,sqrt(3.0)/2.0,sqrt(2.0)/2.0,0.5,0.0}) ) < tol );
32  auto X = cos(E);
33  auto Y = sin(E);
34  REQUIRE( frobenius( atan2(Y,X) - E ) < tol );
35  }
36 
37 ADD_TEST("expr_functions_exponential","[expression]")
38  {
39  double tol = 1.0e-12;
40  auto E = expr({0.0,1.0,2.0,3.0});
41  REQUIRE( frobenius( log(exp(E)) - E ) < tol );
42  REQUIRE( frobenius( log10(pow(10.0,E)) - E ) < tol );
43  }
44 
45 ADD_TEST("expr_functions_power","[expression]")
46  {
47  double tol = 1.0e-12;
48  auto E = expr({0.0,1.0,2.0,3.0});
49  auto E2 = expr({0.0,1.0,4.0,9.0});
50  REQUIRE( frobenius( pow(E,2.0) - E2 ) < tol );
51  REQUIRE( frobenius( sqrt(E2) - E ) < tol );
52  }
53 
54 ADD_TEST("expr_functions_complex","[expression]")
55  {
56  double tol = 1.0e-12;
57  double pi = std::acos(-1.0);
58  std::complex<double> j(0.0,1.0);
59  auto P = expr({0.0,pi/6.0,pi/4.0,pi/3.0,pi/2.0});
60  auto R = cos(P);
61  auto I = sin(P);
62  auto Z = exp( j*make_complex(P) );
63  REQUIRE( frobenius( R - realpart(Z) ) < tol );
64  REQUIRE( frobenius( I - imagpart(Z) ) < tol );
65  REQUIRE( frobenius( P - argument(Z) ) < tol );
66  REQUIRE( frobenius( P + argument(conjugate(Z)) ) < tol );
67  }
68 
69 ADD_TEST("expr_functions_measure","[expression]")
70  {
71  double tol = 1.0e-12;
72  std::vector<double> r {3.0, 5.0, 8.0, 7.0};
73  std::vector<double> i {4.0,12.0,15.0,24.0};
74  std::vector<double> a {5.0,13.0,17.0,25.0};
75  auto R = expr(r);
76  auto I = expr(i);
77  auto Z = make_complex(R,I);
78  auto A = expr(a);
79  REQUIRE( frobenius( abs(Z) - A ) < tol );
80  }
81 
82 #endif
Expression< 1, NumberS > abs(const Expression< 1, NumberS > &A)
Returns the std::abs() of an Expression.
Definition: functions_measure.cpp:29
Expression< 1, NumberS > exp(const Expression< 1, NumberS > &A)
Returns the std::exp() of an Expression.
Definition: functions_exponential.cpp:29
Overloads expr() for std::vector<Number> and (C++11 only) std::initializer_list<Number> ...
Expression< 1, NumberS > pow(const Expression< 1, NumberS > &A, const Expression< 1, NumberS > &B)
Returns A^B, an Expression base raised to an Expression power.
Definition: functions_power.cpp:53
Expression< 1, NumberS > sin(const Expression< 1, NumberS > &A)
Returns the std::sin() of an Expression.
Definition: functions_trig.cpp:30
An interface used to fill containers from Expression&#39;s (see Matrix::evaluate(), for example)...
Definition: syntax.dox:1
Expression< 1, NumberS > cos(const Expression< 1, NumberS > &A)
Returns the std::cos() of an Expression.
Definition: functions_trig.cpp:60
Arithmetic operators (+,-,*,/) for Expression&#39;s.
Routines for computing Frobenius norms of Expression&#39;s.
Expression< 1, NumberS > sqrt(const Expression< 1, NumberS > &A)
Returns the std::sqrt() of an Expression.
Definition: functions_power.cpp:30
Function overloads (sin, exp, etc) for Expression&#39;s.
Expression< 1, NumberS > log10(const Expression< 1, NumberS > &A)
Returns the std::log10() of an Expression.
Definition: functions_exponential.cpp:89
Expression< 1, NumberS > atan2(const Expression< 1, NumberS > &Y, const Expression< 1, NumberS > &X)
Returns the std::atan2(y,x) of a real Expression.
Definition: functions_trig.cpp:212
Expression< 1, NumberC > make_complex(const Expression< 1, NumberS > &A)
Promotes a real Expression into a complex one.
Definition: functions_complex.cpp:122
Expression< 1, NumberS > log(const Expression< 1, NumberS > &A)
Returns the std::log() of an Expression.
Definition: functions_exponential.cpp:59


Results: [PASS]


Go back to Summary of /test programs.