mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
parent
dc6f322975
commit
2ca13dd45a
@ -180,13 +180,14 @@ void test2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Test function to find *minima* for the function
|
* @brief Test function to find *maxima* for the function
|
||||||
* \f$f(x)= \cos x\f$
|
* \f$f(x)= \cos x\f$
|
||||||
* in the interval \f$[0,12]\f$
|
* in the interval \f$[0,12]\f$
|
||||||
* \n Expected result: \f$\pi\approx 3.14159265358979312\f$
|
* \n Expected result: \f$\pi\approx 3.14159265358979312\f$
|
||||||
*/
|
*/
|
||||||
void test3() {
|
void test3() {
|
||||||
// define the function to minimize as a lambda function
|
// define the function to maximize as a lambda function
|
||||||
|
// since we are maximixing, we negated the function return value
|
||||||
std::function<double(double)> func = [](double x) { return std::cos(x); };
|
std::function<double(double)> func = [](double x) { return std::cos(x); };
|
||||||
|
|
||||||
std::cout << "Test 3.... ";
|
std::cout << "Test 3.... ";
|
||||||
|
@ -212,7 +212,7 @@ void test1() {
|
|||||||
std::complex<double>(0., -2.) // known expected roots
|
std::complex<double>(0., -2.) // known expected roots
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialize root approximations with random values */
|
/* initialize root approximations with random values */
|
||||||
for (int n = 0; n < roots.size(); n++) {
|
for (int n = 0; n < roots.size(); n++) {
|
||||||
roots[n] = std::complex<double>(std::rand() % 100, std::rand() % 100);
|
roots[n] = std::complex<double>(std::rand() % 100, std::rand() % 100);
|
||||||
roots[n] -= 50.f;
|
roots[n] -= 50.f;
|
||||||
|
Loading…
Reference in New Issue
Block a user