% 用线性插值和抛物线插值计算 sin(0.3367)
%
clc
clear; 

% 插值节点
X = [0.32, 0.34, 0.36];
% 插值节点函数值
Y= [0.314567, 0.333487, 0.352274];
%
% 插值点
x = 0.3367; 

% 线性插值
% 插值节点
x0 = X(1); 
x1 = X(2); 
% 节点函数值
y0 = Y(1);
y1 = Y(2);
% 插值函数
y = y0*(x-x1)/(x0-x1) + y1*(x-x0)/(x1-x0);
fprintf('线性插值计算结果：%.6f\n',y)

% 抛物线插值
% 插值节点
x0 = X(1); 
x1 = X(2);
x2 = X(3); 
% 节点函数值
y0 = Y(1);
y1 = Y(2);
y2 = Y(3);
% 插值函数
y = y0*(x-x1)*(x-x2)/((x0-x1)*(x0-x2)) + ...
    y1*(x-x0)*(x-x2)/((x1-x0)*(x1-x2)) + ...
    y2*(x-x0)*(x-x1)/((x2-x0)*(x2-x1));
fprintf('抛物线插值计算结果：%.6f\n',y);

%精确值
exact = sin(x);
fprintf('精确值: %.6f\n',exact);
