Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要得到一个离散和的函数。 我的意思是另一个函数的离散总和,而不是数组! 我有Array的功能。如何为自定义 Func 修改它。
public static double Sum(double[] A1, double t1, double t2) { double s = 0; for(long i = t1; i < t2; i++) { s += A1[i]; } return s; }
这是一个答案。 正如您在调用此函数的 main 方法中所见,没有必要正确填充边界。它不取决于您将如何对边界进行排序。
public static double DiscreteSum(Func<double, double> F1, double t1, double t2) { double s = 0; for(long i = (t1<t2)?t1:t2; i < (t1<t2)?t2:t1; i++) { s += F1(i); } return s; }