2023-08-15 17:05:15
发布于:河北
#include <iostream>
#include <cmath>
using namespace std;
enum ExtremeType {
MINIMUM,
MAXIMUM
};
struct ExtremePoint {
double x;
double y;
double value;
ExtremeType type;
};
double f(double x, double y) {
return pow(x, 2) - pow(y, 2);
}
bool isExtremePoint(double (*f)(double, double), double x, double y, double precision) {
double dx = (f(x + precision, y) - f(x - precision, y)) / (2 * precision);
double dy = (f(x, y + precision) - f(x, y - precision)) / (2 * precision);
if (abs(dx) < precision && abs(dy) < precision) {
return true;
}
return false;
}
void findExtremePoints(double (*f)(double, double), double xMin, double xMax, double yMin, double yMax, double precision) {
for (double x = xMin; x <= xMax; x += precision) {
for (double y = yMin; y <= yMax; y += precision) {
if (isExtremePoint(f, x, y, precision)) {
ExtremePoint point;
point.x = x;
point.y = y;
point.value = f(x, y);
if (point.value > 0) {
point.type = MAXIMUM;
} else {
point.type = MINIMUM;
}
cout << "Extreme point at (" << point.x << ", " << point.y << "), value: " << point.value << ", type: ";
if (point.type == MAXIMUM) {
cout << "Maximum" << endl;
} else {
cout << "Minimum" << endl;
}
}
}
}
}
int main() {
double xMin = -1;
double xMax = 1;
double yMin = -1;
double yMax = 1;
double precision = 0.01;
findExtremePoints(f, xMin, xMax, yMin, yMax, precision);
return 0;
}
这里空空如也
有帮助,赞一个