gpt4 book ai didi

c# - 计算给定 X Y 系列的局部最大值/最小值

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:25:17 45 4
gpt4 key购买 nike

我有一个由 Point2D 组成的数组(它有两个成员,xy),例如,Point2D[]点。您可以将此数组视为 X Y 图上的一系列点。数组的排序方式是从较小的 Point2D.X 到较大的 Point2D.X

我的问题很简单:如何找到局部最大值/最小值的点(以及这些点前后的相应项目索引)?回想一下,局部最大/最小值在数学上定义为 dy/dx=0。所以我的任务是我需要找到 dy/dx=0 的那些点。

请注意,极值点可能位于也可能不位于 Point2D 数组内,因为图形是平滑曲线,而不是线性分段折线。极值点可以是数组内两点的中点。例如。

是否有任何现有的库/组件已经在 C# 中执行此操作?

这是我的方法:

public class Point2D
{
public double X;
public double Y;
}

public class PointWithIndex
{
// the extreme point where dy/dx=0
public Point2D ExtremePoints;
// the index of the array for the point that locates right before this ExtremePoints
public int PrevItemIndex;

}

public static List<PointWithIndex> FindLocalExtrema(List<Point2D> xyPoints)
{
// the algorithm to find the max/min points of xyPoints
}

最佳答案

我建议运行一个循环 0 < i < n - 1,检查 P[i - 1].Y < P[i].Y && P[i + 1].Y < P[i].Y,那么 P[i] 是一个最大值。对 min 做同样的事情。

关于c# - 计算给定 X Y 系列的局部最大值/最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10116790/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com