欢迎来到天天文库
浏览记录
ID:58575150
大小:14.00 KB
页数:2页
时间:2020-10-19
《曲线拟合(数值-(C语言)).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、(1)曲线拟合:#include#include#defineMAX100voidmain(){inti,j,k,m,n,N,mi;floattmp,mx;floatX[MAX][MAX],Y[MAX],x[MAX],y[MAX],a[MAX];printf("输入拟合多项式的次数:");scanf("%d",&m);printf("输入给定点的个数n及坐标(x,y):");scanf("%d",&N);printf("");for(i=0;i2、i<=m;i++){for(j=i;j<=m;j++){tmp=0;for(k=0;kmx){mi=i;mx=fabs(X[i][j]);}if(j3、=Y[j];Y[j]=Y[mi];Y[mi]=tmp;for(k=j;k<=m;k++){tmp=X[j][k];X[j][k]=X[mi][k];X[mi][k]=tmp;}}for(i=j+1;i<=m;i++){tmp=-X[i][j]/X[j][j];Y[i]+=Y[j]*tmp;for(k=j;k<=m;k++)X[i][k]+=X[j][k]*tmp;}}a[m]=Y[m]/X[m][m];for(i=m-1;i>=0;i--){a[i]=Y[i];for(j=i+1;j<=m;j++)a[i]-=X[i][j]*a[j];a[i]/=X[i][i];}printf(4、"所求的二次多项式为:");printf("P(x)=%f",a[0]);for(i=1;i<=m;i++)printf("+(%f)*x^%d",a[i],i);}输入拟合多项式的次数:2输入给定点的个数n及坐标(x,y):51,25,32,48,3-1,5所求的二次多项式为:P(x)=3.+(-0.)*x^1+(0.)*x^2Pressanykeytocontinue
2、i<=m;i++){for(j=i;j<=m;j++){tmp=0;for(k=0;kmx){mi=i;mx=fabs(X[i][j]);}if(j3、=Y[j];Y[j]=Y[mi];Y[mi]=tmp;for(k=j;k<=m;k++){tmp=X[j][k];X[j][k]=X[mi][k];X[mi][k]=tmp;}}for(i=j+1;i<=m;i++){tmp=-X[i][j]/X[j][j];Y[i]+=Y[j]*tmp;for(k=j;k<=m;k++)X[i][k]+=X[j][k]*tmp;}}a[m]=Y[m]/X[m][m];for(i=m-1;i>=0;i--){a[i]=Y[i];for(j=i+1;j<=m;j++)a[i]-=X[i][j]*a[j];a[i]/=X[i][i];}printf(4、"所求的二次多项式为:");printf("P(x)=%f",a[0]);for(i=1;i<=m;i++)printf("+(%f)*x^%d",a[i],i);}输入拟合多项式的次数:2输入给定点的个数n及坐标(x,y):51,25,32,48,3-1,5所求的二次多项式为:P(x)=3.+(-0.)*x^1+(0.)*x^2Pressanykeytocontinue
3、=Y[j];Y[j]=Y[mi];Y[mi]=tmp;for(k=j;k<=m;k++){tmp=X[j][k];X[j][k]=X[mi][k];X[mi][k]=tmp;}}for(i=j+1;i<=m;i++){tmp=-X[i][j]/X[j][j];Y[i]+=Y[j]*tmp;for(k=j;k<=m;k++)X[i][k]+=X[j][k]*tmp;}}a[m]=Y[m]/X[m][m];for(i=m-1;i>=0;i--){a[i]=Y[i];for(j=i+1;j<=m;j++)a[i]-=X[i][j]*a[j];a[i]/=X[i][i];}printf(
4、"所求的二次多项式为:");printf("P(x)=%f",a[0]);for(i=1;i<=m;i++)printf("+(%f)*x^%d",a[i],i);}输入拟合多项式的次数:2输入给定点的个数n及坐标(x,y):51,25,32,48,3-1,5所求的二次多项式为:P(x)=3.+(-0.)*x^1+(0.)*x^2Pressanykeytocontinue
此文档下载收益归作者所有