Numerical analysis (implemented in php) 1: Laplace Interpolation

Source: Internet
Author: User

 

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.

 

<? Php

/*

* 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.