ラグランジュの補間法とか

自分用メモ。

ラグランジュの補間法ってのを使えば、与えられた点を通る波線を作れるらしい。
このへんを参考に。
数式をプログラムで表現しよう

[php] <?php $list = array( 10, 1, 6, 2, 3, 6, 4, 9, 8, 5 );

$xx = $yy = array();

// 適当に xx群(0 ~ 100)、yy群を作る for ($i=0;$i<count($list);$i++) { $xx = $i * 10; $yy = $list[$i]; }

// 変換 $xx2 = $yy2 = array(); for ($i=$xx[0];$i<$xx[count($xx) - 1];$i++) { $xx2 = $i; $yy2 = P($i) ; }

print_r($xx2); print_r($yy2);

exit();

function L($k, $v) { global $xx, $yy; $d = (double) 1; for ($i=0;$i<count($xx);$i++) { if ($k != $i) { $d *= ($v - $xx[$i]) / ($xx[$k] - $xx[$i]); } } return $d;

}

function P($v) { global $xx, $yy; $d = (double) 0; for ($i=0;$i<count($xx);$i++) { $d += $yy[$i] * L($i, $v); } return $d; }[/php]