Hermitian (Hermite) interpolation and its MATLAB program

Source: Internet
Author: User
Tags sin








%hermite.m% of Hermitian polynomial and error estimate matlab Main program% input amount: X is n+1 node (x_i,y_i) (i =, ..., n+1) horizontal vector, y is the ordinate vector,% with F ' (x_i) =y ' _i (i =,...
, n+1) is the vector Y1 of the element; %x is an M interpolation point entered as a vector, M satisfies |f~ (2n+2) (x) |≤m% in [A, b]: f~ (2n+2) (x) represents the 2n+2 derivative of f (x), the amount of the output: vector y is the interpolation at vector x, error limit r,2n+1 order Hermitian interpolation polynomial h_
K and its coefficients vector%h_c, error formula Wcgs and its coefficient vector cw.
FUNCTION[Y,R,HC,HK,WCGS,CW] = Hermite (x,y,y1,x,m) n = length (X);


m = length (x);
For t = 1:m z = x (t);
H = 0;
Q = 1;

C1 = 1;
    For k = 1:n s = 0;
    V = 1;
            For i = 1:n if k ~= i s = s + (1/(X (k)-X (i)));
        V = CONV (V,poly (x (i)))/(x (k)-X (i));
    End end h = Poly (X (k));
    g = ([0 1]-2 * H * s);% note Do not write 1-2*h*s, because it is a polynomial subtraction, the lower order polynomial front must be filled with 0, the book error, Wasting my night time g = g * Y (k) + H * Y1 (k);
    H = h + conv (G,conv (v,v));%hermite interpolation polynomial B = poly (X (k));
    b2 = conv (b,b);
Q = conv (Q,B2);
End Hc = H;
Hk = Poly2sym (H);
Q = poly2sym (q);
For i = 1:2*n C1 = C1 * I;
End WCGS = M * Q/C1;
Cw = M * Q/C1;
Y (t) = Polyval (hc,x (t));
R (t) = Polyval (cw,x (t)); End


%hermite.m% of Hermitian polynomial and error estimate matlab Main program% input amount: X is n+1 node (x_i,y_i) (i =, ..., n+1) horizontal vector, y is the ordinate vector,% with F ' (x_i) =y ' _i (i =,...
, n+1) is the vector Y1 of the element; %x is an M interpolation point entered as a vector, M satisfies |f~ (2n+2) (x) |≤m% in [A, b]: f~ (2n+2) (x) represents the 2n+2 derivative of f (x), the amount of the output: vector y is the interpolation at vector x, error limit r,2n+1 order Hermitian interpolation polynomial h_
K and its coefficients vector%h_c, error formula Wcgs and its coefficient vector cw.
FUNCTION[Y,R,HC,HK,WCGS,CW] = Hermite (x,y,y1,x,m) n = length (X);


m = length (x);
For t = 1:m z = x (t);
H = 0;
Q = 1;

C1 = 1;
    For k = 1:n s = 0;
    V = 1;
            For i = 1:n if k ~= i s = s + (1/(X (k)-X (i)));
        V = CONV (V,poly (x (i)))/(x (k)-X (i));
    End end h = Poly (X (k));
    g = ([0 1]-2 * H * s);% note Do not write 1-2*h*s, because it is a polynomial subtraction, the lower order polynomial front must be filled with 0, the book error, Wasting my night time g = g * Y (k) + H * Y1 (k);
    H = h + conv (G,conv (v,v));%hermite interpolation polynomial B = poly (X (k));
    b2 = conv (b,b);
Q = conv (Q,B2);
End Hc = H;
Hk = Poly2sym (H);
Q = poly2sym (q);
For i = 1:2*n C1 = C1 * I;
End WCGS = M * Q/C1;
Cw = M * Q/C1;
Y (t) = Polyval (hc,x (t));
R (t) = Polyval (cw,x (t));
 End



From this picture is better than Lagrange and Newton interpolation, but when the interpolation is more, that is, the number of Hermitian polynomial is high after the error will become very large. Don't believe us to try.

We still use Sinx, but this time we use 5 points.

X 0 PI/6 Pi/4 PI/3 Pi/2

Y 0 0.5 0.7071 0.8660                       1 Y1 1 0.8660 0.7071 0.5 0

>> X = [0 pi/6 pi/4 PI/3 PI/2]; Y = [0 0.5 0.7071 0.8660 1]; Y1 = [1 0.8660 0.7071 0.5 0];
>> M = 1;
>> x = linspace (0, Pi, +);
>> [Y,R,HC,HK,WCGS,CW] = Hermite (x,y,y1,x,m)
>> y1 = sin (X);  
>> ErrorBar (X,y,r, '. G ')  
>> hold on  
>> plot (x, Y, ' or ', x, Y, '. k ', X, Y1, '-B ');  
>> legend (' Error ', ' Sample point ', ' Hermitian interpolation estimate ', ' sin (x) ');  


It can be seen that the fitted polynomial deviates from the Sinx from the x=2.5, and the error formula also fails. This is the high-level interpolation oscillation problem we need to talk about later.



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.