为c中的一组趋势线指定不同的权重

为c中的一组趋势线指定不同的权重,c,combinations,trendline,C,Combinations,Trendline,我有一张有12条不同趋势线的图表。我想通过将所有12条趋势线的值相加来生成一条趋势线,如下所示: for (i = 0, cumulativeTrendValue = 0; i < 12; ++i) { cumulativeTrendValue += trendLine[i]; } for (weight = 1; weight < 12; weight++) { int currentWeight = weight; for (i = 0, cumul

我有一张有12条不同趋势线的图表。我想通过将所有12条趋势线的值相加来生成一条趋势线,如下所示:

for (i = 0, cumulativeTrendValue = 0; i < 12; ++i)
{
     cumulativeTrendValue += trendLine[i];
}
for (weight = 1; weight < 12; weight++)
{
    int currentWeight = weight;

    for (i = 0, cumulativeTrendValue = 0; i < 12; i++)
    {
        cumulativeTrendValue += trendLine[i] * currentWeight;

        if (currentWeight > 1)
            currentWeight--;
    }

    /* Use cumulativeTrendValue someway */
}
for(i=0,cumulativeTrendValue=0;i<12;++i)
{
累积趋势值+=趋势线[i];
}
然后,我将这个cumulativeTrendLine的值输入到另一个函数中。 这很简单。但现在我想通过 将3种不同权重中的1种分配给12条趋势线中的每一条。例如,第一个 通过为每条趋势线分配1的权重来创建累积趋势线;这个 下一步将通过为第一条趋势线指定权重2,为第二条趋势线指定权重1来创建 把趋势线等放在一边,让人感到恶心

现在我确信这已经在这里被问到和回答过了,但是我已经花了2个小时 试图在c中找到一个实现,但无法。 (顺便说一句,如果你想知道的话,这不是家庭作业。你可以看看我在过去几年里的其他问题来证实这一点。)


所以,我的问题是:我可以用什么关键词来找到这个问题以前的答案。或者,如果你今天的心情特别好,你能在这里提供一个问题/答案的链接吗

然而,如果你想按照问题中所述的算法来做,你可以在电流之外有另一个循环,在旧的内部循环中有一个倒计时的计数器。大概是这样的:

for (i = 0, cumulativeTrendValue = 0; i < 12; ++i)
{
     cumulativeTrendValue += trendLine[i];
}
for (weight = 1; weight < 12; weight++)
{
    int currentWeight = weight;

    for (i = 0, cumulativeTrendValue = 0; i < 12; i++)
    {
        cumulativeTrendValue += trendLine[i] * currentWeight;

        if (currentWeight > 1)
            currentWeight--;
    }

    /* Use cumulativeTrendValue someway */
}
for(权重=1;权重<12;权重++)
{
int currentWeight=重量;
对于(i=0,cumulativeTrendValue=0;i<12;i++)
{
cumulativeTrendValue+=趋势线[i]*当前权重;
如果(当前重量>1)
当前权重--;
}
/*以某种方式使用cumulativeTrendValue*/
}

我不确定我是否理解你的问题,但我猜你要找的术语是。那么,为什么不简单地
cumulativeTrendValue+=weight*trendLine[I]