西电计算方法第三次作业
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第四章习题
1利用函数y 二..x 在X 1 =100,X 2 =121处的值,计算-..115的近似值,并估计误差。
1
n
x — X ・
解:LMx) = ' y 」k (x),l k (x) -
7 X k - X i
y °(x) =10, %(x) =11
估计误差:卜帀—^(115) = 10.724-10.714 =0.01
于是 N(x)=16x 7x(x-1) 一 2.5x(x-1)(x-2)
x(x-1)(x-2)(x-4)
6
Ljx)二 y °l °(x) %l 1(x) =10 x -121 100-121 11
x -100
121-100
.LM115) =10
115-121 100-121 11 115-100 121-100 75
7 10.714 一 115
N°(0.125 0.125t) =0.79618— 0.02284t— 0.003395t(t -1) —0.000527t(t — 1)(t - 2) 当0.125+0.125t=0.1581 时,t=0.2648 代入上式得f(0.1581)=0.790615
当0.125t+0.125=0.636 时,t=4.088 代入上式得f(0.636)=0.646062
上机作业
例1:已知函数表:
xi 0.56160 0.56280 0.56401 0.56521
yi 0.82741 0.82659 0.82577 0.82495
用三次拉格朗日插值多项式求x=0.5635时的函数近似值
C语言程序设计:
# in clude
float Lagrange(float x[],float y[],float xx,int n)
{
int i,j;
float *a,yy=0;
a=new float[ n];
for(i=0;i<=n _1;i++)
{
a[i]=y[i];
for(j=0;j<=n _1;j++)
if(j!=i) a[i]*=(xx-x[j])/(x[i]-x[j]);
yy+=a[i];
}
delete a;
return yy;
}
void mai n()
{
float x[4]={0.56160,0.56280,0.56401,0.56521};
float y[4]={0.82741,0.82659,0.82577,0.82495};
float xx=0.5635,yy;
yy=Lagra nge(x,y,xx,4);
prin tf("x=%f,y=%f\n",xx,yy);
}
运行结果:
x=0.563500
y=0.826116
g *C:\DocuMents and Settings\Ad>inistrator\Debug\Cpp1.exe 1^0.563500/9=0.826116
Press any key to cont in Lie
例2:已知函数表
xi 0.4 0.55 0.65 0.8 0.9
yi 0.41075 0.57815 0.69675 0.88811 1.02652 用牛顿插值多项式求M(0.596)和2 (0.895 )。C语言程序设计:
# in clude
# define N 4
void Differen ce(float x[],float y[],i nt n)
{
float *f=new float[ n+1];
int k,i;
for(k=1;k<=n ;k++)
{
f[0]=y[k];
for(i=0;i f[i+1]=(f[i]-y[i])/(x[k]-x[i]); y[k]=f[k]; } delete f; return; } void mai n() { int i; float b,varx=0.596; float x[N+1]={0.4,0.55,0.65,0.8,0.9}; float y[N+1]={0.41075,0.57815,0.69675,0.88811,1.02652}; Differe nce(x,y,N); b=y[N]; for(i=N-1;i>=0;i--) b=b*(varx-x[i])+y[i]; prin tf("N n( %f)=%f',varx,b); } 运行结果: N n(0.596)=0.631918 N n(0.895)=1.019368