您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 计算方法上机题doc
第八题:一,题目从函数表x0.00.10.1950.30.4010.5f(x)0.398940.396950.391420.381380.368120.35206出发,用下列方法计算f(0.15),f(0.31),f(0.47)的近似值:(1)分段线性插值;(2)分段二次插值;(3)全区间上拉格朗日插值(要求一次性输入整张函数表,并利用计算机选择在插值计算中所需的结点)。二,基本方法(1)先选取两个结点xi1与xi使x[xi1,xi],然后在区间[xi1,xi]上作线性插值,即得f(x)≈xxxxyxxxxyLiiiiiiiix11111)(。(2)选取距点x最近的三个结点xi1,xi,xi1进行二次插值,即取f(x)≈)]([)(111,12iikikjijjkjkxxxxyLx。(3)n=5,))...()()...())...()()...(()()(11011000(xxxxxxxxxxxxxxxxylyLnkkkkkknkknkkknkknxx三,计算结果(1)x0.150.310.47f(x)0.3940390.3800670.356927(2)x0.150.310.47f(x)0.3944820.3802250.361399(3)x0.150.310.47f(x)0.3944730.3802190.357222四,结果分析编程基本按照课本套公式,方法从(1)至(3),计算结果越来越精确。五,源程序(1)#includestdio.hintmain(void){inti,j;doublea[6],b[6],x,y;printf(Enterx:);for(i=0;i6;i++)scanf(%lf,&a[i]);printf(Enterf(x):);for(i=0;i6;i++)scanf(%lf,&b[i]);for(j=0;j3;j++){printf(Enterx:);scanf(%lf,&x);for(i=0;xa[i];i++);y=b[i-1]*(x-a[i])/(a[i-1]-a[i])+b[i]*(x-a[i-1])/(a[i]-a[i-1]);printf(x=%lf,,x);printf(y=%lf\n,y);}return0;}(2)#includestdio.hintmain(void){inti,j;doublea[6],b[6],x,y;printf(Enterx:);for(i=0;i6;i++)scanf(%lf,&a[i]);printf(Enterf(x):);for(i=0;i6;i++)scanf(%lf,&b[i]);for(j=0;j3;j++){printf(Enterx:);scanf(%lf,&x);for(i=0;xa[i];i++);if((a[i+1]-x)(x-a[i-2])){y=b[i-1]*(x-a[i])/(a[i-1]-a[i])*(x-a[i+1])/(a[i-1]-a[i+1]);y=y+b[i]*(x-a[i-1])/(a[i]-a[i-1])*(x-a[i+1])/(a[i]-a[i+1]);y=y+b[i+1]*(x-a[i-1])/(a[i+1]-a[i-1])*(x-a[i])/(a[i+1]-a[i]);printf(x=%lf,,x);printf(y=%lf\n,y);}else{y=b[i-2]*(x-a[i-1])/(a[i-2]-a[i-1])*(x-a[i])/(a[i-2]-a[i]);y=y+b[i-1]*(x-a[i-2])/(a[i-1]-a[i-2])*(x-a[i])/(a[i-1]-a[i]);y=y+b[i]*(x-a[i-2])/(a[i]-a[i-2])*(x-a[i-1])/(a[i]-a[i-1]);printf(x=%lf,,x);printf(y=%lf\n,y);}}return0;}(3)#includestdio.hintmain(void){inti,j,k;doublea[6],b[6],x,y,p;printf(Enterx:);for(i=0;i6;i++)scanf(%lf,&a[i]);printf(Enterf(x):);for(i=0;i6;i++)scanf(%lf,&b[i]);for(j=0;j3;j++){y=0;printf(Enterx:);scanf(%lf,&x);for(i=0;i6;i++){p=1;for(k=0;k6;k++){if(k!=i)p=p*(x-a[k])/(a[i]-a[k]);}y=y+p*b[i];}printf(x=%lf,,x);printf(y=%lf\n,y);}return0;}六,附图(1)(2)(3)第九题:一,题目已知直升机旋转机翼外形曲线轮廓线上的某些型值点及端点处的一阶导数值y`(x0)=1.86548,y`(x18)=-0.046115,试计算该曲线上横坐标为2,4,6,12,16,30,60,110,180,280,400,515处点的纵坐标(要求该曲线具有二阶光滑度)。k0123456二,基本方法根据课本图4-9流程图及追赶法解方程。三,计算结果x246121630y7.83433110.47688012.35848516.57965319.09317325.386597x60110180280400515y32.80436936.64788635.91714129.36842716.7991410.524459四,结果分析利用追赶法求M[i],比高斯消去法步骤更简单,虽然结果有微小偏差,尤其在s[515]处与课本结果偏差较大。但在精度要求不高的情况下,追赶法可以减少工作量,提高工作效率。五,源程序#includestdio.hxk0.523.18.017.9528.6539.6250.65yk5.287949.413.8420.224.928.4431.1k131415161718xk364.4416.3468494507520yk20.914.87.83.71.50.2k789101112xk78104.6156.6208.6260.7312.5yk3536.536.634.631.026.34intmain(void){inti,j;doublea[19],b[19],h[19],s[18],t[18],g[19],x,y,p,q,f[19],m[20],n[20];printf(输入左端点一阶导:);scanf(%lf,&p);printf(输入右端点一阶导:);scanf(%lf,&q);printf(Enterx:);for(i=0;i19;i++)scanf(%lf,&a[i]);printf(Enterf(x):);for(i=0;i19;i++)scanf(%lf,&b[i]);for(i=0;i19;i++)h[i]=a[i]-a[i-1];for(i=1;i18;i++)s[i]=h[i]/(h[i]+h[i+1]);for(i=1;i18;i++)t[i]=1-s[i];for(i=1;i18;i++)g[i]=6/(h[i]+h[i+1])*((b[i+1]-b[i])/h[i+1]-(b[i]-b[i-1])/h[i]);g[0]=6/h[1]*((b[1]-b[0])/h[1]-p);g[18]=6/h[18]*(q-(b[18]-b[17])/h[18]);f[1]=0.5;for(i=2;i19;i++)f[i]=t[i-1]/(2-s[i-1]*f[i-1]);n[1]=g[0]/2;for(i=2;i20;i++)n[i]=(g[i-1]-s[i-1]*n[i-1])/(2-s[i-1]*f[i-1]);m[19]=n[19];for(i=18;i0;i--)m[i]=n[i]-f[i]*m[i+1];printf(输出M:\n);for(i=1;i20;i++)printf(%lf,m[i]);for(j=0;j12;j++){printf(\n);printf(Enterx:);scanf(%lf,&x);for(i=0;xa[i];i++);y=m[i]*(a[i]-x)*(a[i]-x)*(a[i]-x)/h[i]/6;y=y+m[i+1]*(x-a[i-1])*(x-a[i-1])*(x-a[i-1])/h[i]/6;y=y+(b[i-1]-m[i]*h[i]*h[i]/6)*(a[i]-x)/h[i];y=y+(b[i]-m[i+1]*h[i]*h[i]/6)*(x-a[i-1])/h[i];printf(f(x):%lf,y);}return0;}六,附图第十二题一,题目某类疾病发生率y‰和年龄段x(每五年为一段,例如0-5岁为第一段,6-10岁为第二段)之间有形如ebxay的关系。试根据观测得到的如下数据表,用最小二乘法确定式中的参数a和b,并计算相应的均方误差与最大偏差。x123456789y0.8982.383.071.842.021.942.222.774.02x10111213141516171819y4.765.466.5310.916.522.535.750.661.681.8二,基本方法(1)将非线性方程化为线性方程,对ebxay等号两边取对数得到bxaylnln。(2)按照最小二乘法的原始定义,不对方程进行变换,而均方误差的方程式,通过求解非线性方程组来解决问题,此时要用到牛顿迭代法。三,计算结果(1)a=0.681361,b=0.230620,e=77.307455,m=18.328522(2)第一次:a=0.721560,b=0.249856,e=17.925350,m=8.1115274第二次:a=0.239368,b=0.310747,e=5.430872,m=3.467987.四,结果分析由以上结果对比,第二种方法结果更加精确,但是采用迭代法计算时,又必须多次选择初值才有可能取得较好的结果。五,源程序(1)#includestdio.h#includemath.hintmain(void){inti;doublea,b,e,m,a0,a1,b0,b1,y1,y2,x[19],y[19];for(i=0;i19;i++)x[i]=i+1;printf(x:);for(i=0;i19;i++)printf(%lf,x[i]);printf(\ny:);for(i=0;i19;i++)scanf(%lf,&y[i]);for(i=0;i19;i++)y[i]=log(y[i]);a0=a1=b0=b1=y1=y2=0;for(i=0;i19;i++){a1=a1+x[i];y1=y1+y[i];b0=b0+x[i];b1=b1+pow(x[i],2);y2=y2+x[i]*y[i];}a0=19;b=(y2-y1*(b0/a0))/(b1-a1*(b0/a0));a=(y1-b*a1)/a0;a=exp(a);for(i=0;i19;i++)y[i]=exp(y[i]);e=m=0;for(i=0;i19;i++)e=e+pow((a*exp((i+1)*b)-y[i]),2);for(i=0;i18;i++){if(pow((a*exp((i+1)*b)-y[i]),2)m)m=pow((a*exp((i+1)*b)-y[i]),2);else;}printf(a=%lfb=%lfe=%lfm=%lf\n,a,b,e/19,sqrt(m));return0;}(2)#includestdio.h#includemath.hintmain(void){inti,j;doublea,b,e,m,f,f1,f2,g,g1
本文标题:计算方法上机题doc
链接地址:https://www.777doc.com/doc-2041752 .html