一个数学计算问题

2019-04-01 13:51发布

问题:

假设有起始值2000,结束值15000,通过
第2个数=2000 x(1+key)
第3个数=第2个数 x(1+key)
第4个数=第3个数 x(1+key)
最终第1300个数=15000
求这个key,用c#代码该怎么写

回答1:

double start = 2000.0000;
double end = 15000.0000;
double key;
key=Math.Pow(end/start, 1d / 1300d);

double end1 =Math.Pow(key, 1300d) * 2000d;
//测试最终end1约等于15000,应该是这样吧



回答2:

     double start = 2000;
        double end = 15000;
        double key;
        double dd = 1300;
        key = Math.Pow(end / start, 1 / dd) - 1;

        Console.WriteLine(key);

        double result = start;

        for (var i = 0; i < 1300; i++)
        {
            result *= (1 + key);
        }
        Console.WriteLine(result);

        Console.ReadKey();


回答3:

static void Main(string[] args)
{
    double from = 2000d;
    double to = 15000d;
    int count = 1300;
    double key = Cal(from, to, count);
    Console.WriteLine(key);
    Console.ReadLine();
}

static double Cal(double from, double to, int count)
{
    double key = Math.Pow(to / from, 1d / (count - 1)) - 1;
    return key;
}


回答4:

startNum * (1+key)^1300-1 = endNum

  1+key = (1300-1)√endNum/startNum

  key = (1300-1)√endNum/startNum - 1