我正在尝试循环下面的迭代,代码在下面,我也会尝试将其分解。
<?php
function intr($LoanRequired, $TermMonths, $MonthlyPayment, $rate) {
$intr= $LoanRequired * pow((1 + $rate), $TermMonths) + $MonthlyPayment * ((pow((1 + $rate), $TermMonths) - 1) / $rate);
return $intr;
}
$x0=0.008;
$x1=0.025;
$LoanRequired=20000;
$TermMonths=120;
$MonthlyPayment=-271.09;
$x2=$x0-(((intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0))*($x0-$x1))/(intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0)-intr($LoanRequired,$TermMonths,$MonthlyPayment,$x1)));
print_r($x2);
$intr = $LoanRequired * pow((1 + $x2), $TermMonths) + $MonthlyPayment * ((pow((1 + $x2), $TermMonths) - 1) / $x2);
while( $intr>=-1 || $intr<=1 ) {
return ;
}
?>
$x0=0.008;
这不会改变,$x0 是第一个猜测
$x1=0.025;
这不会改变 $x1 是第二个猜测
$LoanRequired=20000;
$TermMonths=120;
$MonthlyPayment=-271.09;
该函数中来自表单的所有变量(所有这些都将根据用户输入的内容而改变)
function intr($LoanRequired, $TermMonths, $MonthlyPayment, $rate) {
$intr= $LoanRequired * pow((1 + $rate), $TermMonths) + $MonthlyPayment * ((pow((1 + $rate), $TermMonths) - 1) / $rate);
return $intr;
$rate 变为首先是 $x0,然后是 $x1 和 $x2 等。
$intr = $LoanRequired * pow((1 + $x0), $TermMonths) + $MonthlyPayment * ((pow((1 + $x0), $TermMonths) - 1) / $x0);
首先需要输入上面的公式(首先是 $x0,然后是 $x1,因为它们是两个静态的)如果结果为 <1 或 >-1(
如果前两个静态) ,则整个过程停止猜测不符合执行此操作所需的标准
$x2=$x0-(((intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0))*($x0-$x1))/( intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0)-intr($LoanRequired,$TermMonths,$MonthlyPayment,$x1)));
在循环中。
在这种情况下 $x2 将 =0.0082002592938519 然后将其放入
$intr = $LoanRequired * pow((1 + $x0), $TermMonths) + $MonthlyPayment * ((pow((1 + $x0), $TermMonths) - 1) / $x0); 再次,如果不满足条件,则继续循环,直到满足 $x3、$x4 等条件,
之后需要输入此公式 $apr=((pow(($x0+1), 12))-1)*100;
($x0 显然会更改为 $x1、$x2、$x3 等,具体取决于哪个值是 <1 和 >-1。
我试图把这个进入 while 循环(或任何与此相关的循环),但有一些困难。
I am trying to loop the below iteration, the code is below and i will try and break it down aswell.
<?php
function intr($LoanRequired, $TermMonths, $MonthlyPayment, $rate) {
$intr= $LoanRequired * pow((1 + $rate), $TermMonths) + $MonthlyPayment * ((pow((1 + $rate), $TermMonths) - 1) / $rate);
return $intr;
}
$x0=0.008;
$x1=0.025;
$LoanRequired=20000;
$TermMonths=120;
$MonthlyPayment=-271.09;
$x2=$x0-(((intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0))*($x0-$x1))/(intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0)-intr($LoanRequired,$TermMonths,$MonthlyPayment,$x1)));
print_r($x2);
$intr = $LoanRequired * pow((1 + $x2), $TermMonths) + $MonthlyPayment * ((pow((1 + $x2), $TermMonths) - 1) / $x2);
while( $intr>=-1 || $intr<=1 ) {
return ;
}
?>
$x0=0.008;
this doesn't change, $x0 is the first guess
$x1=0.025;
this doesn't change $x1 is the second guess
$LoanRequired=20000;
$TermMonths=120;
$MonthlyPayment=-271.09;
All variables that will come from a form (all of these will change depending on what the user inputs)
function intr($LoanRequired, $TermMonths, $MonthlyPayment, $rate) {
$intr= $LoanRequired * pow((1 + $rate), $TermMonths) + $MonthlyPayment * ((pow((1 + $rate), $TermMonths) - 1) / $rate);
return $intr;
in this function $rate becomes $x0 at first, then $x1 and $x2 etc.
$intr = $LoanRequired * pow((1 + $x0), $TermMonths) + $MonthlyPayment * ((pow((1 + $x0), $TermMonths) - 1) / $x0);
first it needs to go into this formula above, ($x0 first and then $x1 as they are the two static ones) the whole process stops if the result turns out to be <1 or >-1
if the first two static guesses do not meet the criteria it then needs to do this
$x2=$x0-(((intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0))*($x0-$x1))/(intr($LoanRequired,$TermMonths,$MonthlyPayment,$x0)-intr($LoanRequired,$TermMonths,$MonthlyPayment,$x1)));
in a loop.
In this case $x2 will =0.0082002592938519 which will then be put into
$intr = $LoanRequired * pow((1 + $x0), $TermMonths) + $MonthlyPayment * ((pow((1 + $x0), $TermMonths) - 1) / $x0);
again and if it does not meet the criteria it continues the loop until it does with $x3, $x4 etc
after that it needs to go into this formula $apr=((pow(($x0+1),12))-1)*100;
(the $x0 would obviously change to $x1, $x2, $x3 etc depending on which value was <1 and >-1.
I am trying to put this into a while loop,(or any loop for that matter) but having some difficulty.
发布评论
评论(1)
让我们从设置开始
然后 x2 变为
现在
,如果有下一步,则不再需要当前的 $x0/$i0 。当前的 $x1/$i1 变成 $x0/$i0 , $x2/$i2 变成 $x1/$i1
你这样做 while ($i2 <= -1 || $i2 >= 1) ,即
while (abs($i2) >= 1)
打印
但是如果这有任何重要性,您应该在 https://mathoverflow.net/ 此方法是否可以安全地用于 IEEE 浮点数(我的猜测是不是)。
Let's start with setting
Then x2 becomes
and
Now, if there is a next step you don't need the current $x0/$i0 any more. The current $x1/$i1 become $x0/$i0 and $x2/$i2 become $x1/$i1
And you do that while ($i2 <= -1 || $i2 >= 1), i.e.
while ( abs($i2) >= 1 )
prints
But if this is of any importance you should ask over at https://mathoverflow.net/ whether this method is safe to use with IEEE floats (my guess is it's not).