Secant method of iteration into PHP

tdsii

New Member
How would i turn the secant method of iteration into php?The formula is xi+1= xi - (f(xi) (xi-xi+1))/f(xi)-f(xi-1)where f = function and i is an iteration.so xi+1 is the next iteration after xiSo far I have seen this, but there is somethning wrong somewhere in it so i want to make one from scratch, unless someone here can see what is wrong with it?\[code\]while ((abs($y0 - $y1) > FINANCIAL_ACCURACY) && ($i < FINANCIAL_MAX_ITERATIONS)) { $rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0); $x0 = $x1; $x1 = $rate; if (abs($rate) < FINANCIAL_ACCURACY) { $y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv; } else { $f = exp($nper * log(1 + $rate)); $y = $pv * $f + $pmt * (1 / $rate + $type) * ($f - 1) + $fv; } $y0 = $y1; $y1 = $y; $i++; } \[/code\]Thanksforgot to add, FINANCIAL_ACCURACY is defined as\[code\]define('FINANCIAL_ACCURACY', 1.0e-6);\[/code\]
 
Back
Top