Numerical Analysis (implemented in php) 1: Laplace interpolation

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.