举个例子,希望有所帮助:
function
main()
%
牛顿插值
clear
all;
close
all;
clc;
x=[0.5,0.6,0.4];
y=[-0.6931,-0.5108,-0.9163];
[p,q]=ex23(x,y);
x=0.54;
%线性插值:取插值节点
0.5,0.6
y1=q(1)+q(2)*(x-0.5);
fprintf('线性插值的结果:%.4f\n',y1);
%二次插值:取插值节点
0.5,0.6
y2=y1+q(3)*(x-0.5)*(x-0.5);
fprintf('二次线性插值的结果:%.10f\n',y2);
%
中,对于[p,q]=ex23(x,y)在哪定义?
function
[p,q]=ex23(x,y)
p
=
x.*y;
q
=
x+y;
结果:
线性插值的结果:-0.1895
二次线性插值的结果:-0.1903580800
>>