I have a graph I am trying to replicate:

GAP Graph

I have the following PHP code:

 $sale_price = 25000;
 $future_val = 5000;
 $term = 60;

 $x = $sale_price / $future_val;
 $pts = array();
 $pts[] = array($x,0);
 for ($i=1; $i<=$term; $i++) {
   $y = log($x+0.4)+2.5;
   $pts[] = array($i,$y);
   echo $y . " <br>\n";


The formula is:


I got that by using the Online Function Grapher at http://www.livephysics.com/

Thanks in advance!!

  • 1
    What actually issues you have already experienced? – zerkms Jan 12 '11 at 3:20
  • You should describe what isn't working in your current code. – Matt Ball Jan 12 '11 at 3:20
  • For one thing, the formula in the code doesn't match the one given. $y = -log($x + .4) + 2.5 (or, less weirdly, $y = 2.5 - log($x + .4)) would work better. – cHao Jan 12 '11 at 3:26
  • I don't know. I'm not very good at putting formulas together. I can code them if they're decent, but this is a raw math function and ... I'm having a brainfart converting it to code. – Erick Jan 12 '11 at 3:37
  • As far as what isn't working - the loop does nothing to change the value because log($x + .4) is always the same. I'm not changing $x at any point and not sure how it needs to be done in this case. – Erick Jan 12 '11 at 3:39

Should be

$y = 2.5 - log($i + .4)

X values are the loan term, which you have assigned to $i.

Also, why is your loan term max value 60? Did you convert years to months? Make sure the equation is changed accordingly.

Not quite sure of the validity of your equation though. Check out graph: http://www.wolframalpha.com/input/?i=y+%3D+ln%28x+%2B+0.4%29+%2B+2.5

  • 1
    +1: For WolframAlpha. Oh, and the rest of your answer looks legit. ;) – Fake Code Monkey Rashid Jan 12 '11 at 3:48
  • At some point, the - was omitted. – Erick Jan 12 '11 at 3:50
  • And the term is in months, even tho the graph shows years. That gives more granularity in points and term can be non-whole years (39 mo). And X should be the factor of sale price to final value to give a starting point. X cannot be the term because then it's just decrementing by gibberish values, isn't it? Maybe I'm wrong. Probably. I hate logarithmic algebra! – Erick Jan 12 '11 at 3:53
  • $y = $x - log($i + .4); – Erick Jan 12 '11 at 3:54
  • 1
    Thanks, domesterr - you got me going in the right direction. This doesn't have to be exact. That graph is just a generalization to represent the values and that's all I need at this point. Thanks again! – Erick Jan 12 '11 at 4:05

Your Answer

