资源描述:
《数值分析第三次大作业》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数值分析第三次大作业数值分析第三次大作业姓名:陈怡然学号:380911122010/6/16数值分析第三次大作业数值分析第三次大作业一、设计方案:运用newton迭代法,求解已给方程的根对应的。并根据题中所给的u,t,z的二维数表对z进行插值得到,并使用最小二乘法曲面拟合法对z=f(x,y)进行拟合,在所给的条件下停止运算。将带入z=f(x,y)和p(x,y)求出所求的值,并比较。二、源程序:#defineN6//矩阵的阶;#defineM4//方程组未知数个数;#defineEPSL1.0e-12//迭代的精度水平;#defineMAXDIGIT1.0e-21
2、9#defineSIGSUM1.0e-7#defineL500//迭代最大次数;#defineK10//最小二乘法拟合时的次数上限;#defineX_NUM11#defineY_NUM21#defineOUTPUTMODE1//输出格式:0--输出至屏幕,1--输出至文件#include#includedoublemat_u[N]={0,0.4,0.8,1.2,1.6,2.0},mat_t[N]={0,0.2,0.4,0.6,0.8,1.0},mat_ztu[N][N]={{-0.5,-0.34,0.14,0.94,2.06,3
3、.5},{-0.42,-0.5,-0.26,0.3,1.18,2.38},{-0.18,-0.5,-0.5,-0.18,0.46,1.42},{0.22,-0.34,-0.58,-0.5,-0.1,0.62},{0.78,-0.02,-0.5,-0.66,-0.5,-0.02},{1.5,0.46,-0.26,-0.66,-0.74,-0.5},},mat_val_z[X_NUM][Y_NUM]={0},数值分析第三次大作业init_tuvw[4]={1,2,1,2},mat_crs[K][K]={0};FILE*p;intmain(){inti,j,x,y,k
4、min,tmp=0;doubletmpval;intgetval_z(double,double,int,int);intleasquare();voidresult_out(int);if(OUTPUTMODE){p=fopen("c:\Result.txt","w+");fprintf(p,"计算结果:");fclose(p);}for(i=0;i5、elseprintf("迭代超过最大次数,计算结果可能不准确!");if(kmin=leasquare()){printf("近似表达式已求出!");for(i=0;i<8;i++)for(j=0;j<5;j++)tmp+=getval_z(0.1*(i+1),0.5+0.2*(j+1),i,j);if(!tmp){printf("迭代求解z=f(x*,y*)完毕。");for(x=0;x<8;x++){for(y=0;y<5;y++){tmpval=0;数值分析第三次大作业for(i=0;i6、){tmpval=tmpval+mat_crs[i][j]*pow(0.1*(x+1),i)*pow(0.5+0.2*(y+1),j);}}if(OUTPUTMODE){p=fopen("c:\Result.txt","at+");fprintf(p,"x*[%d]=%f,y*[%d]=%f:f(x*[%d],y*[%d])=%.12le,p(x*[%d],y*[%d])=%.12le",x+1,0.1*(x+1),y+1,0.5+0.2*(y+1),x+1,y+1,mat_val_z[x][y],x+1,y+1,tmpval);fclose(p);}el
7、seprintf("x[%d]=%f,y[%d]=%f:f(x*[%d],y*[%d])=%.12le,p(x*[%d],y*[%d])=%.12le",x+1,0.1*(x+1),y+1,0.5+0.2*(y+1),x+1,y+1,mat_val_z[x][y],x+1,y+1,tmpval);}}}printf("结果见C:\Result.txt!");getchar();}else{printf("近似表达式未求出,增大K值后重试");getchar();}}intgetval_z(doublex,doubley,inti,intj)//牛顿迭代
8、法求方程的解。{数值分析