1 / 14

实验 1 :拉格朗日插值

实验 1 :拉格朗日插值. 经过 个点, ,构造一个 n 次多项式,形如: 使得 成立。 其中 为插值基函数。. 1 .实验原理. 2 .实验内容. function fi=Lagran_(x,y,xi) % 根据给出的数据向量 x 和 y ,构 % 造拉格朗日插值多项式,并计算在 xi 处的值。 fi=zeros(size(xi)); % 全零阵 np1=length(y); for i=1:np1

apu
Download Presentation

实验 1 :拉格朗日插值

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 实验1:拉格朗日插值 经过 个点, ,构造一个n次多项式,形如: 使得 成立。 其中 为插值基函数。 1.实验原理

  2. 2.实验内容 function fi=Lagran_(x,y,xi) %根据给出的数据向量x和y,构 %造拉格朗日插值多项式,并计算在xi处的值。 fi=zeros(size(xi)); % 全零阵 np1=length(y); for i=1:np1 z=ones(size(xi)); %全1阵 for j=1:np1 if i~=j z=z.*(xi-x(j))/(x(i)-x(j)); %插值基函数 end end fi=fi+z*y(i); end return

  3. 3、例题:已知,利用抛物插值计算 的值。

  4. 实验2:牛顿插值 1.实验原理 经过 个点 ,构造一个n次多项式,形如: 其中 为各阶差商。

  5. K阶差商的计算公式如下:

  6. 2.实验内容 function [C,D]=newpoly(x,y) %牛顿插值 n=length(x); D=zeros(n); D(:,1)=y'; for j=2:n %计算差商矩阵 for k=j:n D(k,j)=(D(k,j-1)-D(k-1,j-1))/(x(k)-x(k-j+1)); end end C=D(n,n); for k=(n-1):-1:1 %构造插值多项式 C=conv(C,poly(x(k))); m=length(C); C(m)=C(m)+D(k,k); end

  7. 3. 例题:函数表为 x 0.40 0.55 0.65 0.80 0.90 1.05 f(x) 0.4075 0.57815 0.69675 0.88811 1.02652 1.2538 利用牛顿插值多项式计算f(0.596)的值

  8. 3.实验内容 function a=ployfit(x,y,w) %最小二乘拟合 m=length(w); G=zeros(m); D=zeros(m,1); for i=1:m for j=1:m G(i,j)=sum(w.*(x.^(i+j-2))); end D(i,1)=sum(w.*y.*(x.^(i-1))); end G=G(1:2,1:2) D=D(1:2) a=G^(-1) *D

More Related