How to calculate the multiplicator in a sum like sum += sum*(mulu^n)

I’ve came with a solution. It gets an approximation of the spending factor because there is no direct formula.

Getting the exact spending factor is too CPU intensive. So, I’m calculating a near approximation first. This value will always be above the solution. I then decrease that number until I’m getting below the total paid amount.

Here is a PHP sample of what I’ve done.

$paymentCount   = 4;
$initialPayment = 10; 
$totalPaid      = 1560;

//----- precalculate the factor based on total payment for faster computation
//----- this predefined factor will always be above our final factor

$estimatedSpendingFactor = exp(log($totalPaid) / $paymentCount);

//----- find the estimated spending factor

    $estimatedSpendingFactor -= 0.0001;

    $y = $initialPayment * (pow($estimatedSpendingFactor, $paymentCount) - 1) 
                         / ($estimatedSpendingFactor-1);
while ($y > $totalPaid);


printf("The spending factor is %f\n", $estimatedSpendingFactor);

the output will be :

The spending factor is : 5.000000

Browse More Popular Posts

Leave a Comment