欢迎来到天天文库
浏览记录
ID:16121648
大小:73.50 KB
页数:9页
时间:2018-08-08
《数值分析实验答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验0截断误差与舍入误差#include"stdio.h"#include"math.h"constdoubleln2=0.693147190546;constdoublee1=5e-6;voidmain(){intsign;doubles;longi;s=0.0;sign=1;i=1;while(fabs(ln2-s)>=e1){s+=(1.0/i)*sign;sign=-sign;i++;}printf("n=%ld",i-1);getch();}实验1拉格朗日插值法编写拉格朗日插值法通用
2、子程序,并用以下函数表来上机求,。x0.00.10.1950.30.4010.5f(x)0.398940.396950.391420.381380.368120.35206#includemain(){staticfloatLx[10],Ly[10];intn,i,j;floatx,y,p;printf("entern=");scanf("%d",&n);printf("enterxi");for(i=0;i3、nteryi");for(i=0;i4、i++){p=1;for(j=0;j#include5、h>floatgs(floata[20][20],floatb[20],intn){inti,j,k,l;floats;k=1;while(k!=n+1){if(a[k][k]!=0){for(i=k+1;i<=n+1;i++){a[i][k]=a[i][k]/a[k][k];b[i]=b[i]-a[i][k]*b[k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-a[i][k]*a[k][j];}}k=k+1;}for(k=n+1;k>=1;k--){s=0;for(6、l=k+1;l<=n+1;l++)s=s+a[k][l]*b[l];b[k]=(b[k]-s)/a[k][k];}return0;}main(){staticfloatb[20],Lx[20],Ly[20],c[20][20],ct[20][20],a[20][20];intm,n,i,j,k=0,l;floats,rtn;printf("enterm=");scanf("%d",&m);printf("entern=");scanf("%d",&n);printf("enterxi");for7、(i=1;i<=m;i++)scanf("%f",&Lx[i]);printf("enteryi");for(i=1;i<=m;i++)scanf("%f",&Ly[i]);for(i=1;i<=m;i++){c[i][1]=1;for(j=2;j<=n+1;j++)c[i][j]=Lx[i]*c[i][j-1];}for(i=1;i<=m;i++)for(j=1;j<=n+1;j++)ct[j][i]=c[i][j];for(i=1;i<=n+1;i++)for(j=1;j<=n+1;j++)8、a[i][j]=0;for(i=1;i<=n+1;i++)b[i]=0;for(i=1;i<=n+1;i++)for(k=1;k<=n+1;k++)for(j=1;j<=m;j++)a[i][k]=a[i][k]+ct[i][j]*c[j][k];for(i=1;i<=n+1;i++)for(j=1;j<=m;j++)b[i]+=ct[i][j]*Ly[j];gs(a,b,n);printf("Theresultis:");for(i=1;i<=n+1;i++){
3、nteryi");for(i=0;i4、i++){p=1;for(j=0;j#include5、h>floatgs(floata[20][20],floatb[20],intn){inti,j,k,l;floats;k=1;while(k!=n+1){if(a[k][k]!=0){for(i=k+1;i<=n+1;i++){a[i][k]=a[i][k]/a[k][k];b[i]=b[i]-a[i][k]*b[k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-a[i][k]*a[k][j];}}k=k+1;}for(k=n+1;k>=1;k--){s=0;for(6、l=k+1;l<=n+1;l++)s=s+a[k][l]*b[l];b[k]=(b[k]-s)/a[k][k];}return0;}main(){staticfloatb[20],Lx[20],Ly[20],c[20][20],ct[20][20],a[20][20];intm,n,i,j,k=0,l;floats,rtn;printf("enterm=");scanf("%d",&m);printf("entern=");scanf("%d",&n);printf("enterxi");for7、(i=1;i<=m;i++)scanf("%f",&Lx[i]);printf("enteryi");for(i=1;i<=m;i++)scanf("%f",&Ly[i]);for(i=1;i<=m;i++){c[i][1]=1;for(j=2;j<=n+1;j++)c[i][j]=Lx[i]*c[i][j-1];}for(i=1;i<=m;i++)for(j=1;j<=n+1;j++)ct[j][i]=c[i][j];for(i=1;i<=n+1;i++)for(j=1;j<=n+1;j++)8、a[i][j]=0;for(i=1;i<=n+1;i++)b[i]=0;for(i=1;i<=n+1;i++)for(k=1;k<=n+1;k++)for(j=1;j<=m;j++)a[i][k]=a[i][k]+ct[i][j]*c[j][k];for(i=1;i<=n+1;i++)for(j=1;j<=m;j++)b[i]+=ct[i][j]*Ly[j];gs(a,b,n);printf("Theresultis:");for(i=1;i<=n+1;i++){
4、i++){p=1;for(j=0;j#include5、h>floatgs(floata[20][20],floatb[20],intn){inti,j,k,l;floats;k=1;while(k!=n+1){if(a[k][k]!=0){for(i=k+1;i<=n+1;i++){a[i][k]=a[i][k]/a[k][k];b[i]=b[i]-a[i][k]*b[k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-a[i][k]*a[k][j];}}k=k+1;}for(k=n+1;k>=1;k--){s=0;for(6、l=k+1;l<=n+1;l++)s=s+a[k][l]*b[l];b[k]=(b[k]-s)/a[k][k];}return0;}main(){staticfloatb[20],Lx[20],Ly[20],c[20][20],ct[20][20],a[20][20];intm,n,i,j,k=0,l;floats,rtn;printf("enterm=");scanf("%d",&m);printf("entern=");scanf("%d",&n);printf("enterxi");for7、(i=1;i<=m;i++)scanf("%f",&Lx[i]);printf("enteryi");for(i=1;i<=m;i++)scanf("%f",&Ly[i]);for(i=1;i<=m;i++){c[i][1]=1;for(j=2;j<=n+1;j++)c[i][j]=Lx[i]*c[i][j-1];}for(i=1;i<=m;i++)for(j=1;j<=n+1;j++)ct[j][i]=c[i][j];for(i=1;i<=n+1;i++)for(j=1;j<=n+1;j++)8、a[i][j]=0;for(i=1;i<=n+1;i++)b[i]=0;for(i=1;i<=n+1;i++)for(k=1;k<=n+1;k++)for(j=1;j<=m;j++)a[i][k]=a[i][k]+ct[i][j]*c[j][k];for(i=1;i<=n+1;i++)for(j=1;j<=m;j++)b[i]+=ct[i][j]*Ly[j];gs(a,b,n);printf("Theresultis:");for(i=1;i<=n+1;i++){
5、h>floatgs(floata[20][20],floatb[20],intn){inti,j,k,l;floats;k=1;while(k!=n+1){if(a[k][k]!=0){for(i=k+1;i<=n+1;i++){a[i][k]=a[i][k]/a[k][k];b[i]=b[i]-a[i][k]*b[k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-a[i][k]*a[k][j];}}k=k+1;}for(k=n+1;k>=1;k--){s=0;for(
6、l=k+1;l<=n+1;l++)s=s+a[k][l]*b[l];b[k]=(b[k]-s)/a[k][k];}return0;}main(){staticfloatb[20],Lx[20],Ly[20],c[20][20],ct[20][20],a[20][20];intm,n,i,j,k=0,l;floats,rtn;printf("enterm=");scanf("%d",&m);printf("entern=");scanf("%d",&n);printf("enterxi");for
7、(i=1;i<=m;i++)scanf("%f",&Lx[i]);printf("enteryi");for(i=1;i<=m;i++)scanf("%f",&Ly[i]);for(i=1;i<=m;i++){c[i][1]=1;for(j=2;j<=n+1;j++)c[i][j]=Lx[i]*c[i][j-1];}for(i=1;i<=m;i++)for(j=1;j<=n+1;j++)ct[j][i]=c[i][j];for(i=1;i<=n+1;i++)for(j=1;j<=n+1;j++)
8、a[i][j]=0;for(i=1;i<=n+1;i++)b[i]=0;for(i=1;i<=n+1;i++)for(k=1;k<=n+1;k++)for(j=1;j<=m;j++)a[i][k]=a[i][k]+ct[i][j]*c[j][k];for(i=1;i<=n+1;i++)for(j=1;j<=m;j++)b[i]+=ct[i][j]*Ly[j];gs(a,b,n);printf("Theresultis:");for(i=1;i<=n+1;i++){
此文档下载收益归作者所有