0

我正在尝试创建一个大范德蒙德数组的 Func。我可以像这样创建一个 4x3 系统:

Func<double[], double>[] vandermondeSystem =
{
    x =>  x[0]*Math.Pow(1, 0) + x[1]*Math.Pow(1, 1) + x[2]*Math.Pow(1, 2),
    x =>  x[0]*Math.Pow(2, 0) + x[1]*Math.Pow(2, 1) + x[2]*Math.Pow(2, 2),
    x =>  x[0]*Math.Pow(3, 0) + x[1]*Math.Pow(3, 1) + x[2]*Math.Pow(3, 2),
    x =>  x[0]*Math.Pow(4, 0) + x[1]*Math.Pow(4, 1) + x[2]*Math.Pow(4, 2)
}

但是编写像这样的大(比如 100x50)系统是不可行的,所以我认为我需要使用某种循环或递归,但我不知道怎么做。

这个页面解释了如何创建一个匿名递归来实现斐波那契函数,但我不知道如何利用那里解释的方法。

4

1 回答 1

1

根据您当前的代码,您可以轻松地对其进行修改以支持 100x50 等更大的系统。像这样的东西怎么样:

Func<double[], double>[] bigVandermondeSystem = new Func<double[], double>[100];

// Constructing a 100 x 50 Vandermonde System
for (int i = 0; i < 100; i++)
{
    var i1 = i;
    bigVandermondeSystem[i] = x => Enumerable
        .Range(0, 50)
        .Sum(number => x[number] * Math.Pow(i1 + 1, number));
}
于 2017-10-11T10:18:59.710 回答