% 此函数的简短摘要。
% 此函数的详细说明。


function  hermite(x,y)
%% 输入值分配，x_input,y_input均为数组,y_0,y_n为x_0,x_n分别对应的一阶导数值
x_input = x;
y_input = y;

%% 
[~,number] = size(x_input); %获取输入x_input的大小1×number
maxy=0
 
for i =1:number-1
    % 获取相邻两点间的插值函数
     x_ = linspace(x_input(1,i),x_input(1,i+1));

    h=cubic_Hermite(x_input(1,i),x_input(1,i+1),sin(x_input(1,i)),sin(x_input(1,i+1)),cos(x_input(1,i)),cos(x_input(1,i+1)));
    s=polyval(h,x_);

    H=plot(x_,s,'b-');
    hold on;
    
    maxy=max(max(s),maxy);
%     ResHermite=plot(x_,abs(s-sin(x_)),"Color",[0.8 0.2 0.2],"LineStyle","-");
%     hold on;
end

%比较牛顿法

N=my_newton(x,y);
t=linspace(x(1),x(end),1001);
P2=polyval(N,t);
H1=plot(t,P2,'r-');
hold on;
% ResNewTon=plot(t,abs(P2-sin(t)),"Color",[0 0.2 0.2],"LineStyle","-");
% hold on;

%绘制fx
H2=plot(t,sin(t),'g-');
%hold on;

% 显示插值点
H3 =plot(x_input,y_input,'*');

legend([H,H1,H2,H3],{'cubic_hermite','newton','sin(x)','point'})

%框定图像显示位置
maxy=max(max(P2),maxy);
miny=-max(abs(P2));
xlim([x(1) x(end)]);
ylim([2*miny 2*maxy]);
clear;