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..

Link to comment
Share on other sites

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)
*/

?>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.