欧拉的编程功能:微分方程作为参数

时间:2013-12-05 14:48:55

标签: linear-programming approximation calculus

我有一个为Eurler近似编写的编程函数。目前该功能只需3个参数。

  1. 步长
  2. 开始f(x)
  3. 结束f(x)这就是我们的近似值
  4. 每次我必须使用欧拉,我必须继续改变我的函数的微分方程。

    E.g。 euqation 1

    f'(x) = 3x^{2} - 7
    

    等式2

    f'(x) = f(x) + 2
    

    我想发送微分方程作为参数。我该怎么办?

    我正在使用C#,VBA。目前没有安装Matlab。但我愿意尝试使用Python,尽管我是新手。

    ps:我checked on this question. Quite hard to understand the case there...

1 个答案:

答案 0 :(得分:0)

也许这会有所帮助:

我以C#为例

public static double equation(double x, Func<double, double> f)
{
    return f(x);
}

static void Main(string[] args)
{
    //f'(x) = 3x^{2} - 7
    double result1 = equation(5, x => Math.Pow(3 * x, 1 / 2) - 7);

    //f'(x) = f(x) + 2
    double result2 = equation(5, x => x + 2); 

    Console.WriteLine(result1);
    Console.WriteLine(result2);
}