In the course of numerical analysis, I tried to use php to implement it. if you are interested, you can stick it down and try using the Laplace interpolation to give n known points. use polynomial functions to fit and find the fitting function, then, an interpolation process for estimating the value of the unknown point function is f (x) xigma (sum) lk * yk... syntaxHighlighter. all ();
In the field of numerical analysis, try to use php. if you are interested, stick it down and try again.
The Laplace interpolation is an interpolation process that gives n known points and uses polynomial functions to fit and obtain the fitting function, and then estimates the value of an unknown point function.
The interpolation function is f (x) = xigma (sum) lk * yk
This class implements the function of displaying functional images after interpolation.
/*
* Laplace interpolation
* @ Wangbin
**/
Class lags {
Private $ dot = array ();
Public function _ construct ($ array ){
$ This-> dot = $ array;
}
/*
* Calculate lk
**/
Private function get_lk ($ x, $ k ){
$ Num = count ($ this-> dot ['x']);
$ Omiga_xk = 1;
$ Omiga_x = 1;
For ($ I = 0; $ I <$ num; $ I ++ ){
If ($ I! = $ K ){
$ Omiga_xk * = ($ this-> dot ['x'] [$ k]-$ this-> dot ['x'] [$ I]);
$ Omiga_x * = ($ x-$ this-> dot ['x'] [$ I]);
}
}
$ Lk = $ omiga_x/$ omiga_xk;
Return $ lk;
}
Public function get_y ($ x ){
$ Num = count ($ this-> dot ['x']);
$ L = 0;
For ($ k = 0; $ k <$ num; $ k ++ ){
$ Lk = $ this-> get_lk ($ x, $ k );
$ L + = ($ this-> dot ['Y'] [$ k] * $ lk );
}
Return $ L;
}
Public function draw (){
$ Img = imagecreate (500,500 );
Imagecolorallocate ($ img, 255,255, 2 );
$ Num = count ($ this-> dot ['x']);
$ Max = 0;
For ($ I = 0; $ I <$ num; $ I ++) $ max = $ max <$ this-> dot ['x'] [$ I]? $ This-> dot ['x'] [$ I]: $ max;
$ R = 7; // The radius of the vertex
$ Step = 0.1; // step size
For ($ I = 0; $ I <$ num; $ I ++ ){
Imagefilledellipse ($ img, $ this-> dot ['x'] [$ I], $ this-> dot ['Y'] [$ I], $ r, $ r, 1 );
}
For ($ I = $ this-> dot ['x'] [0]-10; $ I <$ max + 10; $ I + = $ step ){
$ Current_x = $ I;
$ Current_y = $ this-> get_y ($ current_x );
$ Next_x = $ I + $ step;
$ Next_y = $ this-> get_y ($ next_x );
Imageline ($ img, $ current_x, $ current_y, $ next_x, $ next_y, 1 );
}
Header ("Content-type: image/png ");
Imagepng ($ img );
Imagedestroy ($ img );
}
}
$ X = new Laplace (array ('x' => array (100,120,220, 240,220,340), 'y' => array )));
$ X-> draw ();
?>
From pcenshao