Jump to content

Complex math problem, how to write it in php


radar

Recommended Posts

This is about the worst math i've ever seen... i HATE math....  any help is appreciated...  The mathematical equation as based on actual math is:

 

n = -log(1-[Pi/(Mq)])/(q log[1+(i/q)])

 

where P = primary_loan ammount, i = interest rate, M = monthly payment and q = presumed # of payments per year (12 all the time)  so in my 'sample' it would be something like

 

P = 100,000, i= .1, M = 1400 and q = 12...  if the math comes out right it should come up with 9.08 or 9.1 if you round (which i dont want to do)

 

no clue how to do this in PHP.. any help appreciated... thanks..

Pretty straightforward

 

<?php 

$primary_loan = 100000;
$interest = 0.1;
$monthly = 1400;
$pay_per_year = 12;

$total = log( 1-(($primary_loan*$interest)/($monthly*$pay_per_year)) ) / 
( $pay_per_year*log(1+($interest/$pay_per_year)) ) * -1;

echo $total; // 9.0821962960889

/*
n = -log(1-[Pi/(Mq)])/(q log[1+(i/q)])

where P = primary_loan ammount, i = interest rate, M = monthly payment
and q = presumed # of payments per year (12 all the time)  so in my
'sample' it would be something like

P = 100,000, i= .1, M = 1400 and q = 12...  if the math comes out right
it should come up with 9.08 or 9.1 if you round (which i dont want to do)
*/

?>

man you guys are awesome....  In my years of programming php I've never had to do this type of math before so figuring out how to write it (being that i suck at math - almost 30 and can barely add and subtract really) was going to be a pain in the butt.....  thank you guys very much for helping me out I really appreciate it!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.