我正在尝试将用简单语言代码编写的数学函数转换为 C#,但我的代码中遇到一个非常简单但非常令人沮丧的错误,即我运行计算的值越多,值就会不断下降。我已附上代码的屏幕截图以及我所返回的内容。我确信这只是我的代码中的一个拼写错误,但我找不到它。如果您需要查看其他内容,请告诉我
这是我的代码:
public static (List<double>, List<double>) CalculateEhlersRoofingFilter(List<double> valuesList, int days)
{
List<double> highPassList = new List<double>();
List<double> roofingFilterList = new List<double>();
int lowerPeriod = days;
int upperPeriod = Utils.MinOrMax((int)Math.Ceiling(lowerPeriod / 0.2083));
double alphaArg = Utils.ToRadians((0.707 * 360) / upperPeriod);
double alphaCos = Math.Cos(alphaArg);
double alpha1;
if (alphaCos != 0)
{
alpha1 = (alphaCos + Math.Sin(alphaArg) - 1) / alphaCos;
}
else
{
alpha1 = 0;
}
double a1 = Math.Exp((-1.414 * 3.14159) / lowerPeriod);
double b1 = 2 * a1 * Math.Cos(Utils.ToRadians((1.414 * 180) / lowerPeriod));
double c2 = b1;
double c3 = (-1 * a1) * a1;
double c1 = 1 - c2 - c3;
for (int i = 0; i < valuesList.Count; i++)
{
double currentValue = valuesList.ElementAt(i);
double prevValue1, prevValue2, prevFilter1, prevFilter2, prevHp1, prevHp2;
if (i >= 1)
{
prevValue1 = valuesList.ElementAt(i - 1);
prevFilter1 = roofingFilterList.ElementAt(i - 1);
prevHp1 = highPassList.ElementAt(i - 1);
}
else
{
prevValue1 = currentValue;
prevFilter1 = currentValue;
prevHp1 = currentValue;
}
if (i >= 2)
{
prevFilter2 = roofingFilterList.ElementAt(i - 2);
prevValue2 = valuesList.ElementAt(i - 2);
prevHp2 = highPassList.ElementAt(i - 2);
}
我想在我的代码中实现什么:
公式返回什么:
我正在使用的输入值:
慕工程0101907
相关分类