ballhogjoni Posted September 22, 2007 Share Posted September 22, 2007 How can I make a loop for this formula? P (1 + r/365)365 Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/ Share on other sites More sharing options...
MmmVomit Posted September 22, 2007 Share Posted September 22, 2007 Not enough information. It looks like you're trying to calculate interest on something. What exactly are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-352791 Share on other sites More sharing options...
d.shankar Posted September 22, 2007 Share Posted September 22, 2007 I hope this could help ! <?php #P(1 + r/365)365 $P=10; #change the P value here $r=5; #change the r value here $div_res=$r/365; $sum_res=$div_res+1; $result=pow($sum_res,365); $finalresult=$result*$P; echo $finalresult; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-352809 Share on other sites More sharing options...
ballhogjoni Posted September 22, 2007 Author Share Posted September 22, 2007 Thank you for the replies. Yes I am trying to calculate daily compunding interest. Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-352998 Share on other sites More sharing options...
cooldude832 Posted September 22, 2007 Share Posted September 22, 2007 Since you are looking for a sigma of something why not do a [code <?php for($i =1; $i <=$num_days; $i++){ $value[$i] = //Some math stuff; } $sum = array_sum($value); ?> Or you can view a a day to day of it etc etc, you might want to might need to try this below however, since you will need compounding interest <?php for($i =1; $i <=$num_days; $i++){ if($i >1){ $j = $i-1; $value[$i] = //Some math stuff using the recursive value; } else{ $value[$i] = //Some math based ont he IV } } ?> Like so, Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353033 Share on other sites More sharing options...
d.shankar Posted September 23, 2007 Share Posted September 23, 2007 Did the code help ? Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353180 Share on other sites More sharing options...
ballhogjoni Posted September 23, 2007 Author Share Posted September 23, 2007 Thank you again. Yes, d.shankar, the code helped. Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353498 Share on other sites More sharing options...
ballhogjoni Posted September 23, 2007 Author Share Posted September 23, 2007 <?php for($i =1; $i <=$num_days; $i++){ if($i >1){ $j = $i-1; $value[$i] = //Some math stuff using the recursive value; } else{ $value[$i] = //Some math based ont he IV } } ?> Whats the recursive value? Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353505 Share on other sites More sharing options...
cooldude832 Posted September 23, 2007 Share Posted September 23, 2007 $value[$j] $value is the daily balance after n days (n is what the value is in it) so you are compounding daily so today's balance = $value[$today-1]*$rate+$value[$today-1] which is that recursive step i showed. Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353511 Share on other sites More sharing options...
ballhogjoni Posted September 23, 2007 Author Share Posted September 23, 2007 if I had 365 days and I wanted to have the script print each day, 1,2,3,4... what type of loop would that be? I have used a foreach() & for() and they didn't work. My code <?php $y=5; $days = ($y*365); $resultDay = array($days); for($i=1; $i<=$days; $i++){ $years=$days-1; } echo $years; ?> Outputs: 1824 Shouldn't it output 1,2,3,4,5,.....1825? Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353536 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 you only echo once. you may want to include the echo in the loop so it happens more than once. Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353543 Share on other sites More sharing options...
ballhogjoni Posted September 23, 2007 Author Share Posted September 23, 2007 Ok great, thanks. The problem now is that it is just repeating 182418241824... It should be saying 1 2 3 4 5 6 7 etc Maybe I am not explaining it well enough...this is what I want the code to do: foreach() day run this code...if there are 365 days this code should run 365 times and I want it to output something 365 times, I.E. foreach($day as $dy) { //some code echo 'somthing'; } Output should look something like this: 1 2 3 4 5 6 etc Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353552 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 for($i=1; $i<=$days; $i++){ echo "$i<BR>"; } I assume this is for a web page, so the line break is <BR>. Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353581 Share on other sites More sharing options...
rarebit Posted September 23, 2007 Share Posted September 23, 2007 Sorry no intermediaries on this one... (play with n for that!) /* Daily Compounded Interest V = D(1 + r/365)365n D is the amount deposited, r is the interest rate, n is the number of years, and V is the final amount. */ function dci($d, $r, $n) { return $d*( pow((1+$r/365), 365*$n) ); } echo "dci: ".dci(10, 2, 3); ref: http://www.math.umd.edu/~rll/cgi-bin/finance.cgi Quote Link to comment https://forums.phpfreaks.com/topic/70239-solved-loop/#findComment-353593 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.