View Single Post
01-24-2013, 09:31 PM   PM User | #4
Old Pedant
Supreme Master coder!

Join Date: Feb 2009
Posts: 24,952
Thanks: 75
Thanked 4,307 Times in 4,274 Posts
Quote:
 F / G: = 1 / N - N / (1 + I)^N - 1 My Problem is when I added value G = 10, I = 10, N =10 I get a result of 93.73 which is wrong. Where i calculate 37.31 as correct. When I do G =1, I = 10, N = 10. I get a result of 3.73, which is correct.
*CLEARLY* if 3.73, is correct for G=1, then the answer should be 37.3 for G=10.

After all, to transform
Code:
`F / G: = 1 / N - N / (1 + I)^N - 1`
to solve for F, all you do is multiply both sides by G:
Code:
```G * ( F / G ) = G * ( 1 / N - N / (1 + I)^N - 1 )
-->>
F = G * ( 1 / N - N / (1 + I)^N - 1 )```
which means the answer for G=10 should be 10 times the answer for G=1.

Let's just translate that pictured formula, exactly, with no simplifications:
Code:
```<!DOCTYPE html>
<html>
<body>
<form id="theForm">
Rate: <input name="rate"/><br/>
Years: <input name="year"/><br>
<input type="button" value="calculate" onclick="fvg()"/>
<hr/>
</form>

<script type="text/javascript">

// UGUS = 1/i - n/( (1+i)^n -1 )

function UGUS( G, i, n )
{
// UGUS formula save that we multiply by G
return G * ( 1/i - ( n / ( Math.pow(1+i,n) - 1 ) ) );
}

function fvg ()
{
var form = document.getElementById("theForm");
var interest = form.rate.value / 100;
var periods = Number( form.year.value );
var power = UGUS( gradient, interest, periods );

form.amount.value = power.toFixed(2); // forget Math.round!

form.interest.value = ( power - gradient ).toFixed(2);

}

</script>
</body>
</html>```
And for G=1, I=10, N=10 indeed I get 3.73
And for G=10, I=10, N=10 indeed I get 37.25
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.