matlab求龙格函数f(x)=1(1+25*x^2)在区间[-1,1]上取n=10的等距节点,分别作多项式插值三次样条插值

matlab求龙格函数f(x)=1(1+25*x^2)在区间[-1,1]上取n=10的等距节点,分别作多项式插值三次样条插值,第1张

x = linspace(-1,1,10);

x1 = linspace(-1,1,100);

y =1/(1+25x^2);

y1 = interp1(x,y,x1,'cubic');

y2 = interp1(x,y,x1,'spline');

figure();

plot(x,y,'ro');

hold on;

plot(x1,y1,'b',x1,y2,'g');

legend('插值点','多项式','三次样条');

clc,clear

x=[01 02 015 0 -02 03];

y=[095 084 0876 106 150 072];

p=polyfit(x,y,2)

xi=-02:001:03;

yi=polyval(p,xi);

X=xi;Y=yi;

fun=inline('c(1)X^2+c(2)X+c(3)','c','X');

[c,resnorm,residual,exitflag]=lsqcurvefit(fun,[1,1,1],X,Y);

c,exitflag

matlab中使用插值函数

插值函数(the function of interpolation )

interp1

调用函数的格式(Syntax)

yi = interp1(x,Y,xi)

yi = interp1(Y,xi)

yi = interp1(x,Y,xi,method)

yi = interp1(x,Y,xi,method,'extrap')

yi = interp1(x,Y,xi,method,extrapval)

pp = interp1(x,Y,method,'pp')

调用格式说明(Description)

yi = interp1(x,Y,xi) 返回矢量X和Y决定的根据输入的节点xi时对应的y的值矢量Y是矢量X的一个函数映射

如果Y是一个矩阵,那么插值结果是一个对应的矩阵

[===================================================

yi = interp1(x,Y,xi) returns vector yi containing elements corresponding to the elements of xi and determined by interpolation within vectors x and Y The vector x specifies the points at which the data Y is given If Y is a matrix, then the interpolation is performed for each column of Y and yi is length(xi)-by-size(Y,2)

===================================================]

yi = interp1(x,Y,xi,method)插值中可以使用的方法: 插值方法 说明 nearest 临近的两点插值 linear 线性插值(默认) spline 三次样条插值 pchip 分段三次Hermite插值多项式插值 cubic (作用于pchip相同) v5cubic 用matlab5版本中断三次样条插值 [====================================================

yi = interp1(x,Y,xi,method) interpolates using alternative methods:

methodDescription

nearestNearest neighbor interpolation

linearLinear interpolation (default)

splinesplineCubic spline interpolation

pchipPiecewise cubic Hermite interpolation

cubic(Same as 'pchip')

v5cubicCubic interpolation used in MATLAB 5

======================================================]

简单程序示例

>>x=[00 01 0195 03 0401 05];

>>y=[039849 039695 039142 038138 036812 035206];

>>plot(x,y);

>>T=interp1(x,y,25,'linear') %线性插值

(返回结果T=03862)

>> T=interp1(x,y,25,'nearest') % 两点插值

(返回结果T=03814)

>>T=interp1(x,y,25,'spline')  % 三次样条插值

(返回结果T =03867)

>>T=interp1(x,y,25,'cubic') %三次插值

(返回结果T =03867)

以上就是关于matlab求龙格函数f(x)=1/(1+25*x^2)在区间[-1,1]上取n=10的等距节点,分别作多项式插值三次样条插值全部的内容,包括:matlab求龙格函数f(x)=1/(1+25*x^2)在区间[-1,1]上取n=10的等距节点,分别作多项式插值三次样条插值、求高手指点,matlab问题.大概是这个样子的,给一组数据,用二次多项式先插值,再拟合.求程序啊、插值的编程使用等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9450308.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存