radar Posted August 19, 2011 Share Posted August 19, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/ Share on other sites More sharing options...
xyph Posted August 19, 2011 Share Posted August 19, 2011 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) */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259504 Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2011 Share Posted August 19, 2011 <?php $P = 100000; $M = 1400; $q = 12; $i = .1; $n = -log(1-($P * $i/($M * $q)))/($q * log(1+($i/$q))); echo $n; ?> 9.0821962960889 Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259505 Share on other sites More sharing options...
radar Posted August 19, 2011 Author Share Posted August 19, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259515 Share on other sites More sharing options...
radar Posted August 19, 2011 Author Share Posted August 19, 2011 Ahh just thought of something else, because the end-user will be able to input their interest rate at 10, 29.5 or any number inbetween 0 and 100%.. how would i use php to modify that into a decimal for use with this equation Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259521 Share on other sites More sharing options...
xyph Posted August 19, 2011 Share Posted August 19, 2011 Divide by 100 $number = 50; $percent = $number / 100; Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259525 Share on other sites More sharing options...
radar Posted August 19, 2011 Author Share Posted August 19, 2011 beautiful. thanks xyph... saves me a ton of hassle within the next day or two... I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/245218-complex-math-problem-how-to-write-it-in-php/#findComment-1259599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.