數(shù)值計(jì)算編程20個(gè)_第1頁(yè)
數(shù)值計(jì)算編程20個(gè)_第2頁(yè)
數(shù)值計(jì)算編程20個(gè)_第3頁(yè)
數(shù)值計(jì)算編程20個(gè)_第4頁(yè)
數(shù)值計(jì)算編程20個(gè)_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、P11,第一題PrivateSubForm_Click()Dima,b,x,sAsDoublea=1b=2s=0.001Dox=(a+b)/2If(x人3-x-1)*(a人3-a-1)<0Thenb=xElsea=xEndIfLoopUntilAbs(x人3-x-1)<sPrintxPrintx人3-x-1EndSub結(jié)果:1.2、P12,第五題PrivateSubForm_Click()Dima,x,sAsDoublea=8s=0.001x=aDop=xx=(p+a/p)/2LoopUntilAbs(x-p)<sPrintxEndSub結(jié)果:2.9863、程序:PrivateSubForm_Click()DimiAsIntegerDimt,a(0To3),pAsDoublet=2Fori=0To3a(i)=InputBox("x("&i&")=")Nextip=a(3)Fori=2To0Step-1p=p*t+a(i)NextiPrintpEndSub結(jié)果:494、程序:PrivateSubForm_Click()Dima,b,sAsDoublea=0.2b=1.34s=(a+b)/2DoIfa*(1-a)*s*(1-s)<0Thenb=sElsea=sEndIfs=(a+b)/2LoopUntilb-a<0.01PrintsEndSub結(jié)果:0.9971093755、程序:PrivateSubForm_click()Dimx,s,pAsDoubleDimiAsIntegerx=101s=10p=1/2/10i=1Dos=s+pp=p/2*(-1)/100*(2*i-1)i=i+1LoopUntilp<0.01PrintsEndSub結(jié)果:10.056、拉格朗日:PrivateSubForm_Click()Dimi,j,nAsIntegerDimx(1To100),y(1To100),p,s,tAsDoublet=2.5n=3Fori=1Tonx(i)=InputBox("x("&i&")=")y(i)=InputBox("y("&i&")=")Nextis=0Fori=1Tonp=1Forj=1TonIfi<>jThenp=p*(t-x(j))/(x(i)-x(j))EndIfNextjs=s+p*y(i)NextiPrintsEndSub結(jié)果:67、課堂埃爾米特插值程序:PrivateSubForm_Activate()Dimx0,y0,x1,y1,g0,g1AsDoublex0=0y0=0x1=1y1=1g0=0g1=2x=0.5a0=-2/(xO-xl)人3bO=1/(xO-xl)人2+2*xO/(xO-xl)人3al=-2/(xl-xO)人3bl=2*xl/(xl-xO)人3+l/(xl-xO)人2kO=l/(xO-xl)人2k1=1/(xl-xO)人2=(x-xl)人2*(aO*x+bO)=(x-xO)人2*(al*x+bl)ggO=kO*(x-xO)*(x-xl)人2ggl=kl*(x-xO)人2*(x-xl)y=1O*yO+1l*yl+ggO*gO+ggl*glPrintyEndSub結(jié)果:O.258、第一個(gè):樣條函數(shù):PrivateSubForm_Activate()Dimx(3),y(3),mO,ml,m2AsDoub1eDimiAsIntegerFori=OTo2x(i)=iy(i)=i*iNextimO=Om2=4hO=x(l)-x(O)hl=x(2)-x(l)a=2/hOb=4/hO+4/hlc=2/hld=(-6*y(l)+6*y(2))/hl人2-(6*y(O)-6*y(l))/hO人2ml=(d-a*mO-c*m2)/bPrintmlEndSub結(jié)果:29、牛頓插值:DimkAsIntegerPrivateSubCombol_C1ick()DimiAsIntegerk=CInt(Combol.Text)Fori=OTo9Textl(2*i).Visib1e=Fa1seTextl(2*i+l).Visib1e=Fa1seLabe1(i).Visib1e=Fa1seNextiFori=0Tok-1WithLabel(i).Visible=True.Top=1560+400*i.Caption="第"&i+1&"點(diǎn):".Left=120EndWithWithText1(2*i).Visible=True.Left=800.Top=1500+400*iEndWithWithText1(2*i+1).Visible=True.Left=1500.Top=1500+400*iEndWithNextiEndSubPrivateSubCommand1_Click()DimiAsIntegerDimsAsDoubles=0Fori=0Tok-1s=s+ff(i)*f1(Text3.Text,i)NextiText2.Text=sEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubForm_Load()DimiAsIntegerFori=2To10Combo1.AddItemiNextiEndSubFunctionff(ByValnAsInteger)DimiAsIntegerDimsAsDoubles=0Ifn=0Thenff=Text1(1).TextExitFunctionEndIfFori=0Tons=s+Text1(2*i+1).Text/f(i,n)Nextiff=sEndFunctionFunctionf(ByValpAsInteger,ByValnAsInteger)DimiAsIntegerDimsAsDoubles=1Fori=0TonIfi<>pThens=s*(Text1(2*p).Text-Text1(2*i).Text)EndIfNextif=sEndFunctionFunctionf1(ByValxAsDouble,ByValnAsInteger)DimiAsIntegerDimsAsDoubleIfn=0Thenf1=1ExitFunctionEndIfs=1Fori=0Ton-1s=s*(x-Text1(2*i).Text)Nextif1=sEndFunction結(jié)果:帶入(1,1),(2,4),(3,7),(4,8),(5,6)得到變量為3.5時(shí),插值結(jié)果為7.835937510、復(fù)化辛普生算法:PrivateSubCommand1_Click()Dimi,nAsIntegerDims,h,xAsDoublea=InputBox("請(qǐng)輸入左端點(diǎn)a:")b=InputBox("請(qǐng)輸入右端點(diǎn)b:")n=InputBox("請(qǐng)輸入分段數(shù)n:")h=(b-a)/ns=f(b)-f(a)x=aFori=1Tonx=x+h/2s=s+4*f(x)x=x+h/2s=s+2*f(x)Nextis=h/6*sText1.Text=sEndSubFunctionf(ByValxAsDouble)Ifx=0Thenf=1ExitFunctionEndIff=Sin(x)/xEndFunction結(jié)果:當(dāng)輸入?yún)^(qū)間為(0,1),分8段,運(yùn)行結(jié)果是0.194311、p153第6題PrivateSubForm_Load()Dims,t,eAsDoubleDimi,kAsIntegert=0k=0s=(t+2)人0.5e=0.001Fori=0To20IfAbs(s-t)<eThenk=1ExitForEndIft=ss=(t+2)人0.5NextiText1.Text=sEndSub結(jié)果:1.82912、p154第18題DimaAsDoublePrivateSubForm_Load()Dimx0,x,eAsDoubleDimiAsIntegerx=5e=0.000001a=InputBox("a=")Fori=0To20x0=xText1.Text=Text1.Text&vbCrLf&f1(x0)Iff1(x0)=0ThenExitForEndIfx=x0-f(x0)/f1(x0)IfAbs(x-x0)<eThenExitForEndIfNextiIfi=20ThenMsgBox"迭代失??!"EndEndIfText1.Text=xEndSubFunctionf(ByValxAsDouble)f=x人3-aEndFunctionFunctionf1(ByValxAsDouble)fl=3*x人2EndFunction結(jié)果:2.188l3、pl55第24題牛頓法PrivateSubForm_Load()Dimx0,eAsDoubleDimiAsIntegerx0=0e=0.000001n=20Iff1(x0)=0ThenMsgBox"奇異"EndEndIfFori=oTo20x0=xIff1(x)=0ThenMsgBox"奇異"EndEndIfx=x0-f(x0)/f1(x0)IfAbs(x-x0)<eThenExitForEndIfNextiIfi=20ThenMsgBox"迭代失??!"EndEndIfText1.Text=xEndSubFunctionf(ByValxAsDouble)f=x人3+2*x人2+10*x-20EndFunctionFunctionf1(ByValxAsDouble)fl=3*x人2+4*x+10EndFunction結(jié)果:1.13714、p155第24題弦截法PrivateSubForm_Load()Dimx0,x1,eAsDoubleDimiAsIntegerx0=0e=0.000001n=20Iff1(x0)=0ThenMsgBox"奇異"EndEndIfx1=x0-f(x0)/f1(x0)Fori=oTo20x=x1-f(x1)/(f(x1)-f(x0))*(x1-x0)IfAbs(x-x1)<eThenExitForEndIfx1=xNextiIfi=20ThenMsgBox"迭代失??!"EndEndIfText1.Text=xEndSubFunctionf(ByValxAsDouble)f=x人3+2*x人2+10*x-20EndFunctionFunctionf1(ByValxAsDouble)fl=3*x人2+4*x+10EndFunction結(jié)果:1.56215、p155第24題快速弦截法PrivateSubForm_Load()Dimx0,x1,eAsDoubleDimiAsIntegerx0=0e=0.000001n=20Iff1(x0)=0ThenMsgBox"奇異"EndEndIfx1=x0-f(x0)/f1(x0)Fori=oTo20x0=x1x1=xx=x1-f(x1)/(f(x1)-f(x0))*(x1-x0)IfAbs(x-x1)<eThenExitForEndIfNextiIfi=20ThenMsgBox"迭代失?。?EndEndIfText1.Text=xEndSubFunctionf(ByValxAsDouble)f=x人3+2*x人2+10*x-20EndFunctionFunctionf1(ByValxAsDouble)fl=3*x人2+4*x+10EndFunction結(jié)果:1.49616、消去法DimnAsIntegerDima(1To10,1To10),b(1To10),x(1To10)AsDoublePrivateSubCombo1_Click()Dimi,jAsIntegerFori=1To100Text1(i).Visible=FalseNextiFori=1To10Text2(i).Visible=FalseText3(i).Visible=FalseNextin=Combo1.TextFori=1TonForj=1TonWithText1((i-1)*n+j).Visible=True.Top=500*i+200.Left=500*j.Height=300EndWithNextjWithText2(i).Visible=True.Top=500*i+200.Left=500*n+800.Height=300EndWithWithText3(i).Visible=True.Top=500*i+200.Left=500*n+1800.Width=700.Height=300EndWithNextiEndSubPrivateSubCommand1_Click()Dimi,j,kAsIntegerDims,rAsDoubleFori=1TonForj=1Tona(i,j)=Text1((i-1)*n+j).TextNextjb(i)=Text2(i).TextNextiFori=1Ton-1Forj=i+1Tonr=a(j,i)/a(i,i)Fork=iTona(j,k)=a(j,k)-r*a(i,k)Nextkb(j)=b(j)-r*b(i)NextjNextiFori=nTo1Step-1s=b(i)Ifi<>nThenForj=iTons=s-a(i,j)*x(j)NextjEndIfx(i)=s/a(i,i)Text3(i).Text=x(i)NextiEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubForm_Load()DimiAsIntegerFori=2To10Combo1.AddItemiNextiEndSub結(jié)果:選擇求解未知數(shù)個(gè)數(shù)為3,再依次輸入A={2,-1,3;4,2,5;1,2,0;}B={1,4,7;}得到x={9,-1,-6}17、追趕法PrivateSubCommand1_Click()Dimi,j,kAsIntegerDimaa(1To4),bb(1To4),cc(1To4),dd(1To4),xx(1To4),g(1To4),f(1To4)AsDoubleDims,rAsDoubleFori=1To4Ifi=1Thenaa(i)=0Elseaa(i)=a(i).TextEndIfbb(i)=b(i).TextIfi=4Thencc(i)=0Elsecc(i)=c(i).TextEndIfdd(i)=d(i).TextNextig(1)=dd(1)/bb(1)f(1)=-cc(1)/bb(1)Fori=2To4g(i)=(dd(i)-aa(i)*g(i-1))/(aa(i)*f(i-1)+bb(i))f(i)=-cc(i)/(aa(i)*f(i-1)+bb(i))Nextixx(4)=g(4)x(4).Text=xx(4)Fori=3To1Step-1xx(i)=g(i)+f(i)*xx(i+1)x(i).Text=xx(i)NextiEndSubPrivateSubCommand2_Click()EndEndSub結(jié)果:依次輸入方程組系數(shù)A={1,1;1,2,1;1,2,3;1,2;},B={3,8,20,ll}得到結(jié)果為X={1,2,3,4;}18、高斯-賽德爾程序如下:PrivateSubCommand1_Click()Dimi,jAsIntegerDimk,t(1To3),s,a(1To3,1To3),b(1To3),x(1To3)AsDoubleFori=1To3Forj=1To3a(i,j)=Text1(i*3+j-3).TextNextjb(i)=Text2(i).Textx(i)=0Nextik=1DoUntilk<0.0001Fori=1To3s=b(i)Forj=1To3Ifj<>iThenText4.Text=ss=s-a(i,j)*x(j)Text5.Text=sEndIfNextjt(i)=s/a(i,i)Ifi=1Thenk=Abs(t(i)-x(i))ElseIfAbs(t(i)-x(i))>kThenk=Abs(t(i)-x(i))EndIfx(i)=t(i)NextiLoopFori=1To3Text3(i).Text=x(i)NextiEndSub運(yùn)行結(jié)果:輸入系數(shù)A={7,5,-3;5,7,1;2,1,7;}B={2,4,-11}得到X={-1.727,2.000,-1.363}19、迭代法程序如下:PrivateSubCommand1_Click()Dimi,jAsIntegerDimk,t(1To3),s,a(1To3,1To3),b(1To3),x(1To3)AsDoubleFori=1To3Forj=1To3a(i,j)=Text1(i*3+j-3).TextNextjb(i)=Text2(i).Textx(i)=0Nextik=1DoUntilk<0.0001Fori=1To3s=b(i)Forj=1To3Ifj<>iThenText4.Text=ss

溫馨提示

  • 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)論