數(shù)值計(jì)算方法_第1頁(yè)
數(shù)值計(jì)算方法_第2頁(yè)
數(shù)值計(jì)算方法_第3頁(yè)
數(shù)值計(jì)算方法_第4頁(yè)
數(shù)值計(jì)算方法_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

數(shù)值計(jì)算方法電氣信息工程學(xué)院班級(jí):電氣1001潘云杰題目1.有方程f(x)=xA5-3*x-1=0,在區(qū)間(1,2)中唯一實(shí)根,若用Newton迭代法求此根,使其誤差不超過10A(-4).程序#include<stdio.h>#include<math.h>voidmain()(doublea,b,eps;doublex,x0,f0,f1,m,n;floatz;printf("Pleaseinputyourabeps\n");scanf("%lf%lf%lf",&a,&b,&eps);z=(a+b)/2;x0=z;m=pow(x0,5);n=pow(x0,4);f0=m-3*x0-1;f1=5*n-3;x=x0-f0/f1;while(fabs(x-x0)>eps)

x0=x;m=pow(x0,5);n=pow(x0,4);f0=m-3*x0-1;f1=5*n-3;x=x0-f0/f1;printf(''x0=%12.10lf,x=%12.10lf\n'',x0,x);}printf("Therootis:%12.10lf\n",x);=leaseinputyourabeps1.iu.uumK0=1.4061S246S0,x=l.3092927199k0=1.3892927199.x=113887924145k(3==1.3887924145,x=l.3887919844Kherootis:li3807919844(2)題日2,設(shè)AX=B(2)A^然=B「57910】「1〕⑴A=68109B=11710871576514x-x+x=5{-x+2x-2x=-3x-2x+3x=6試用高斯列主元消元法求方程組的解程序(1)#include<stdio.h>#include<math.h>#definen4#defineeps1e-10voidmain()(inti,j,det;doubleaa[n][n+1];doublea[n+1][n+2],x[n+1];intGauss();for(i=0;i<n;i++)for(j=0;j<n+1;j++)scanf("%lf",&aa[i][j]);for(i=0;i<n;i++)(for(j=0;j<n+1;j++)printf("%lf",aa[i][j]);printf("\n");}for(i=1;i<=n;i++)for(j=1;j<=n+1;j++)a[i][j]=aa[i-1][j-1];det=Gauss(a,x);if(det!=0)for(i=1;i<=n;i++)printf("\nx[%d]=%f\n",i,x[i]);printf("\n");getch();}intGauss(doublea[][n+2],doublex[n+1])(inti,j,k,r;doublec;for(k=1;k<=n-1;k++)(r=k;for(i=k;i<=n;i++)if(fabs(a[i][k])>fabs(a[r][k]))r=i;if(fabs(a[r][k])<eps)(printf("\ndetA=0.faild!");exit(0);}if(r!=k)(for(j=k;j<=n+1;j++)(c=a[k][j];a[k][j]=a[r][j];a[r][j]=c;}}for(i=k+1;i<=n;i++)(c=a[i][k]/a[k][k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-c*a[k][j];}}if(fabs(a[n][n])<eps)(printf("\ndetA=0.faild!");exit(0);}for(k=n;k>=1;k--)(x[k]=a[k][n+1];for(j=k+1;j<=n;j++)x[k]=x[k]-a[k][j]*x[j];x[k]=x[k]/a[k][k];}return(1);}i?91018IS;9110871S?6515 .essays10.0SSSS31G.頁(yè)句包迎迎迥8. Hi,捕包迎齒起邑9-S總,單『包迥17.10.aSESB0S.7.I*:祿按當(dāng)按做口E.0SS0S07. 6.0000035.,00000S1.00S0S0^ci]=20.S00ij0iSk[2]=-12:00ij00S^[3]=-5.S00ijSiS(2)#include<stdio.h>#include<math.h>#definen3#defineeps1e-10voidmain()(inti,j,det;doubleaa[n][n+1];doublea[n+1][n+2],x[n+1];intGauss();for(i=1;i<=n;i++)for(j=1;j<=n+1;j++)scanf("%lf",&aa[i][j]);for(i=0;i<n;i++)(for(j=0;j<n+1;j++)printf("%lf",aa[i][j]);printf("\n");}for(i=1;i<=n;i++)for(j=1;j<=n+1;j++)a[i][j]=aa[i-1][j-1];det=Gauss(a,x);if(det!=0)for(i=1;i<=n;i++)printf("\nx[%d]=%f\n",i,x[i]);printf("\n");getch();}intGauss(doublea[][n+2],doublex[n+1])(inti,j,k,r;doublec;for(k=1;k<=n-1;k++)(r=k;for(i=k;i<=n;i++)if(fabs(a[i][k])>fabs(a[r][k]))r=i;if(fabs(a[r][k])<eps)(printf("\ndetA=0.faild!");exit(0);}if(r!=k)(for(j=k;j<=n+1;j++)(c=a[k][j];a[k][j]=a[r][j];a[r][j]=c;}}for(i=k+1;i<=n;i++)(c=a[i][k]/a[k][k];for(j=k+1;j<=n+1;j++)a[i][j]=a[i][j]-c*a[k][j];}}if(fabs(a[n][n])<eps)(printf("\ndetA=0.faild!");exit(0);}for(k=n;k>=1;k--)(x[k]=a[k][n+1];for(j=k+1;j<=n;j++)x[k]=x[k]-a[k][j]*x[j];x[k]=x[k]/a[k][k];}return(1);}題日3.已知函數(shù)f(*)f(1+x)的數(shù)表X0.250.300.360.390.45ln(1+x)0.22314360.26236430.30748470.32930370.3715636試用四次牛頓插值法求x=0.275時(shí)的函數(shù)值,并估算誤差。程序#include<stdio.h>#definen4voidmain()(floata[n+1][n+2]={0},s=0,t=1,x;inti,j;printf("pleaseinputxiyi\n");for(i=0;i<n+1;i++)for(j=0;j<2;j++)scanf("%f",&a[i][j]);for(j=1;j<n+2;j++)for(i=j;i<n+1;i++)a[i][j+1]=(a[i][j]-a[i-1][j])/(a[i][0]-a[i-j][0]);

printf("outputxi,yi,cha\n");for(i=0;i<n+1;i++)(for(j=0;j<n+2;j++)printf("%6.7f",a[i][j]);printf("\n");}printf("N%d(x)=",n);for(i=0;i<n+1;i++)(printf("%6.7f",a[i][i+1]);for(j=0;j<i;j++)printf("(x-%3.2f)",a[j][0]);if(i==n)break;printf("+");}printf("\n");printf("x=");scanf("%f",&x);for(i=0;i<n+1;i++)(for(j=0;j<i;j++)t*=(x-a[j][0]);s+=a[i][i+1]*t;}printf("N%d(%4.3f)=%6.7f\n",n,x,s);}真值:ln(1+0.275)=0.2429461誤差:0.2429461-0.2427586=0.0001875pleaseinputxiyi^.253.22314362326643S.363.32748473.3293£i373.3715636outputxi,3990000yt,cha0.22314360.23266430J32748470;32930370.371563600.19941381,58^33990.0606339^.704331712.6356897-16.3656277-210.06657710.800000^7.1522^2163.25221251055.5941162*14<x>=0.2231436+0^19??413a<x-0.25>+12.6356897<x-0.25Xx-@.30>+-210.3665771<x-0.25><x-S.30Xx-0.36>+1855,;5941i62<x-0.25><x-0.30><x-0.36><x-0.39>k=0.275275>=0.2277067題目4.用龍貝格方法求積分[1*!危,要求誤差不超過10J dX 1o-1X程序#include<stdio.h>#include<math.h>#definef(x)(sin(x)/x)#defineMAX5floatRBG(floatp,floatq,intn)(inti;floatsum=0,h=(q-p)/n;for(i=1;i<n;i++)sum+=f(p+i*h);sum+=(f(p)+f(q))/2;return(h*sum);}voidmain()(inti;intn=2,m=0;floatT[MAX+1][2];doublea,b,e;printf("pleaseinputabe\n");scanf("%lf%lf%lf",&a,&b,&e);T[0][1]=RBG(a,b,n);n*=2;for(m=1;m<MAX;m++)(for(i=0;i<m;i++)T[i][0]=T[i][1];T[0][1]=RBG(a,b,n);n*=2;for(i=1;i<=m;i++)T[i][1]=T[i-1][1]+(T[i-1][1]-T[i-1][0])/(pow(4,m)-1);if(fabs(T[m-1][1]-T[m][1])<e)(printf("Answer=%f\n",T[m][1]);getch();return;}}}pleaseinputabe-110.001Answer=l.981041題日5.用四階龍格一一庫(kù)塔法求解!J,r,(0<*0.4)的初值問題?!瞴(0)=1分別取步長(zhǎng).=0.05和h=°」,分析其結(jié)果,保留5位有效數(shù)字。程序#include<stdio.h>#include<math.h>#definef(x,y)(x)-(y)voidmain()(doublea,b,x0,y0,k1,k2,k3,k4,x1,y1,h;intn,i;printf("inputdataa,b,x0,y0,h=\n");scanf("%lf%lf%lf%lf%lf",&a,&b,&x0,&y0,&h);n=(b-a)/h;printf("a=%lf,b=%lf,x0=%lf,y0=%lf,h=%lf\n",a,b,x0,y0,h);printf("%15s%15s%15s\n","n","xry");printf("%15s%15.6f%15.6f\n","0",x0,y0);for(i=0;i<n;i++)for(i=1;i<=n;i++)(x1=x0+h;k1=h*f(x0,y0);k2=h*f(x0+h/2,y0+h*k1/2);k3=h*f(x0+h/2,y0+h*k2/2);k4=h*f(x0+h,y0+h*k3);y1=y0+(k1+2*k2+2*k3+k4)/6;printf("%15d%15.6f%15.6f\n",i,x1,y1);x0=x1;y0=y1;}

getch();X0.解DD回DD0.200000H.4WD凰恩訝,yEPh=getch();X0.解DD回DD0.200000H.4WD凰恩訝,yEPh=c:CTC.EIER01234nputdataa,,0.4,0,1,0.1=0-品訪煎宙苗有=■-6.40^0^83=0.000000茹:=!.■旗曲弦□日SJ=8,100000y1.0000000.9096750.8374620.78163??.740641-.11putdataa,b,xl^,0■4.0.1.■0?困a=0nfi@0@0@^=@?400t5t?t3x@=fi.000000=1_03^!i}00h=E.05^?^0n^i2345678x□.0593090.1^@0000.2^3000a.250^00.3^@000S.3500S0W.4聘聘聘畤?y1-盼我聯(lián)理舊日0.952459

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論