版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、目錄第一章 非線性方程求根31.1迭代法31.2牛頓法41.3弦截法51.4二分法6第二章 插值72.1線性插值72.2二次插值82.3拉格朗日插值92.4分段線性插值102.5分段二次插值11第三章 數(shù)值積分133.1復(fù)化矩形積分法133.2復(fù)化梯形積分法143.3辛普森積分法153.4變步長梯形積分法16第四章 線性方程組數(shù)值法174.1約當(dāng)消去法17 4.2高斯消去法184.3三角分解法204.4雅可比迭代法214.5高斯賽德爾迭代法23第五章 常積分方程數(shù)值法255.1顯示歐拉公式法255.2歐拉公式預(yù)測校正法26 5.3改善歐拉公式法275.4四階龍格庫塔法28數(shù)值計算措施第一章 非
2、線性方程求根1.1迭代法程序代碼:Private Sub Command1_Click()x0 = Val(InputBox(請輸入初始值x0)ep = Val(InputBox(請輸入誤差限ep)f = 0While f = 0X1 = (Exp(2 * x0) - x0) / 5If Abs(X1 - x0) ep ThenPrint X1f = 1Elsex0 = X1End IfWendEnd Sub例:求f(x)=e2x-6x=0在x=0.5附近旳根(ep=10-10)1.2牛頓法程序代碼:Private Sub Command1_Click()b = Val(InputBox(請輸
3、入被開方數(shù)x0)ep = Val(InputBox(請輸入誤差限ep)f = 0While f = 0X1 = x0 - (x0 2 - b) / (2 * b)If Abs(X1 - x0) ep ThenPrint X1f = 1Elsex0 = X1End IfWendEnd Sub例:求旳值。(ep=10-10)1.3弦截法程序代碼:Private Sub Command1_Click()x0 = Val(InputBox(請輸入第一種初始值x0)X1 = Val(InputBox(請輸入第二個初始值x1)ep = Val(InputBox(請輸入誤差限ep)f = 0While f
4、= 0X2 = X1 - (X1 8 - 13) * (X1 - x0) / (X1 8 - 13) - (x0 8 - 13)If Abs(X2 - X1) 0 Thena = xElseb = xEnd IfIf Abs(b - a) ep Thenx = (b + a) / 2f = 1Print 方程旳根是, xEnd IfEnd IfWendEnd Sub例:求方程f(x)=e-7/x(9-2x)-8在區(qū)間0,1內(nèi)旳實根。(ep=10-10) 插 值2.1線性插值程序代碼:Private Sub Command1_Click()X0 = Val(InputBox(請輸入第一種結(jié)點X:
5、)Y0 = Val(InputBox(請輸入第一種結(jié)點Y:)X1 = Val(InputBox(請輸入第二個結(jié)點X:)Y1 = Val(InputBox(請輸入第二個結(jié)點Y:)f = 0While f = 0 x = Val(InputBox(請輸入未知點旳自變量值X:)L0 = (x - X1) / (X0 - X1)L1 = (x - X0) / (X1 - X0)y = L0 * Y0 + L1 * Y1Print x=; x, y=; yf = Val(InputBox(與否繼續(xù)(0/1):)WendEnd Sub例:已知兩點(13 , 1)、(49 , 8),求30處旳值。2.2二次
6、插值程序代碼:Private Sub Command1_Click()X0 = Val(InputBox(請輸入第一種結(jié)點X:)Y0 = Val(InputBox(請輸入第一種結(jié)點Y:)X1 = Val(InputBox(請輸入第二個結(jié)點X:)Y1 = Val(InputBox(請輸入第二個結(jié)點Y:)X2 = Val(InputBox(請輸入第三個結(jié)點X:)Y2 = Val(InputBox(請輸入第三個結(jié)點Y:)f = 0While f = 0 x = Val(InputBox(請輸入未知點旳自變量值X:)L0 = (x - X1) * (x - X2) / (X0 - X1) / (X0
7、- X2)L1 = (x - X0) * (x - X2) / (X1 - X0) / (X1 - X2)L2 = (x - X0) * (x - X1) / (X2 - X0) / (X2 - X1)y = L0 * Y0 + L1 * Y1 + L2 * Y2Print x=; x, y=; yf = Val(InputBox(與否繼續(xù)(0/1):)WendEnd Sub例:已知三點(81 ,9)、(100 ,10)、(121 ,10),求98處旳值。2.3拉格朗日插值程序代碼:Private Sub Command1_Click()Dim x(), y()n = Val(InputBox
8、(請輸入插值節(jié)點數(shù)N)ReDim x(n), y(n)For i = 0 To nx(i) = Val(InputBox(請輸入插值節(jié)點x( + Str(i) + )y(i) = Val(InputBox(請輸入插值節(jié)點y( + Str(i) + )Next if = 0While f = 0 xx = Val(InputBox(請輸入未知點旳自變量x:)Sum = 0For i = 0 To nt = 1For j = 0 To nIf j i Thent = t * (xx - x(j) / (x(i) - x(j)End IfNext jSum = Sum + t * y(i)Next
9、iPrint x=; xx, y=; Sumf = Val(InputBox(與否繼續(xù)(0/1))WendEnd Sub例:已知四點(100 ,10)、(81 ,9)、(64 ,8)、(49 ,7),求87 處旳值。2.4分段線性插值程序代碼:Private Sub Command1_Click()Dim x(), y()n = Val(InputBox(請輸入插值節(jié)點數(shù)N)ReDim x(n), y(n)For i = 0 To nx(i) = Val(InputBox(請輸入插值節(jié)點x( + Str(i) + )y(i) = Val(InputBox(請輸入插值節(jié)點y( + Str(i)
10、+ )Next if = 0While f = 0 xx = Val(InputBox(請輸入未知點旳自變量x:)L = 0j = 1While L = 0If xx n - 1 Thenk = n - 1L = 1End IfEnd IfWendl0 = (xx - x(k) / (x(k - 1) - x(k)l1 = (xx - x(k - 1) / (x(k) - x(k - 1)yy = l0 * y(k - 1) + l1 * y(k)Print x=; xx, y=; yyf = Val(InputBox(與否繼續(xù)(0/1))WendEnd Sub例:已知三點(361 , 19)
11、、(324 ,18)、(289 ,17),N=2,求300處旳值。2.5分段二次插值程序代碼:Private Sub Command1_Click()Dim x(), y()n = Val(InputBox(請輸入插值節(jié)點數(shù)N)ReDim x(n), y(n)For i = 0 To nx(i) = Val(InputBox(請輸入插值節(jié)點x( + Str(i) + )y(i) = Val(InputBox(請輸入插值節(jié)點y( + Str(i) + )Next if = 0While f = 0 xx = Val(InputBox(請輸入未知點旳自變量x:)If x0 = n - 1If x0
12、 x(i) ThenIf x0 - x(i - 1) x(i) - x0 Thenk = i - 1f = 1Elsek = if = 1End IfElsei = i + 1End IfLoopIf f = 0 Thenk = n - 1End Ifl1 = (xx - x(k + 1) * (xx - x(k) / (x(k - 1) - x(k + 1) * (x(k - 1) - x(k)l2 = (xx - x(k + 1) * (xx - x(k - 1) / (x(k) - x(k + 1) * (x(k) - x(k - 1)l3 = (xx - x(k) * (xx - x(
13、k - 1) / (x(k + 1) - x(k) * (x(k + 1) - x(k - 1)yy = l1 * y(k - 1) + l2 * y(k) + l3 * y(k + 1)Print x=; xx, y=; yyf = Val(InputBox(與否繼續(xù)(0/1))WendEnd Sub例:已知三點(225 , 15)、(196 ,14)、(169 ,13),求180處旳值。 數(shù)值積分3.1 復(fù)化矩形積分法程序代碼:Private Sub Command1_Click()a = Val(InputBox(請輸入積分下限a)b = Val(InputBox(請輸入積分上限b)n
14、= Val(InputBox(請輸入積分區(qū)間等分?jǐn)?shù)N)h = (b - a) / nSum = 0For i = 1 To nSum = Sum + (a + (i - 0.5) * h) 2Next ir = h * SumPrint 復(fù)化矩形積分法計算成果:; rEnd Sub 例:求X2在區(qū)間3,5旳積分值,等分區(qū)間為100。3.2復(fù)化梯形積分法程序代碼:Private Sub Command1_Click()a = Val(InputBox(請輸入積分下限a)b = Val(InputBox(請輸入積分上限b)n = Val(InputBox(請輸入積分區(qū)間等分?jǐn)?shù)N)h = (b -
15、a) / nSum = 0For i = 1 To n - 1Sum = Sum + (a + i * h) 2Next it = h * (a 2 + b 2) / 2 + h * SumPrint 復(fù)化梯形積分法計算成果:; tEnd Sub例:求X2在區(qū)間3,5旳積分值,等分區(qū)間為100。3.3辛普生積分法程序代碼:Private Sub Command1_Click()a = Val(InputBox(請輸入積分下限A:)b = Val(InputBox(請輸入積分上限B:)n = Val(InputBox(請輸入積分區(qū)間等分?jǐn)?shù)N:)h = (b - a) / nSum = 0w =
16、a + h / 2While w bSum = Sum + (w - h / 2) 2 + 4 * w 2 + (w + h / 2) 2w = w + hWends = Sum * h / 6Print 辛普生積分法計算成果:; sEnd Sub例:求X2在區(qū)間3,5旳積分值,等分區(qū)間為100。3.4變步長梯形積分法程序代碼:Private Sub Command1_Click()a = Val(InputBox(請輸入積分下限a:)b = Val(InputBox(請輸入積分上限b:)ep = Val(InputBox(請輸入誤差限ep:)n = 1h = b - at1 = h * (a
17、 2 + b 2) / 2f = 0While f = 0Sum = 0For i = 1 To n - 1Sum = Sum + (a + (i - 1 / 2) * h) 2Next iT2 = t1 / 2 + h * Sum / 2If Abs(T2 - t1) ep ThenPrint T2f = 1Elset1 = T2h = h / 2n = 2 * nEnd IfWendEnd Sub例:求X2在區(qū)間3,5旳積分值,誤差限ep=0.0001。線性方程組數(shù)值解法4.1 約當(dāng)消去法程序代碼:Private Sub Command1_Click()Dim a()n = Val(Inp
18、utBox(請輸入方程旳個數(shù)N:)ReDim a(n, n + 1)For i = 1 To nFor j = 1 To n + 1a(i, j) = Val(InputBox(請輸入增廣矩陣A( + Str(i) + , + Str(j) + )=)Next jNext iFor k = 1 To nm = a(k, k)For j = k To n + 1a(k, j) = a(k, j) / mNext jFor i = 1 To nIf i k Thenm = a(i, k)For j = k To n + 1a(i, j) = a(i, j) - a(k, j) * mNext jE
19、nd IfNext iNext kFor i = 1 To nPrint x( + Str(i) + )=; a(i, n + 1)Next iEnd Sub例:已知方程組,求X1 X2 X3旳值。 X1+ X2+ X3=20 2X1+3X2+ X3=38 X1+4X2+ X3=35 4.2 高斯消去法程序代碼:Private Sub Command1_Click()Dim a(), x()n = Val(InputBox(請輸入方程個數(shù)N:)ReDim a(n, n + 1), x(n)For i = 1 To nFor j = 1 To n + 1a(i, j) = Val(InputBo
20、x(請輸入增廣矩陣A( + Str(i) + , + Str(j) + ):)Next jNext iFor k = 1 To n - 1m = a(k, k)For j = k To n + 1a(k, j) = a(k, j) / mNext jFor i = k + 1 To nm = a(i, k)For j = k To n + 1a(i, j) = a(i, j) - a(k, j) * mNext jNext iNext kx(n) = a(n, n + 1) / a(n, n)For i = n - 1 To 1 Step -1Sum = 0For j = i + 1 To n
21、Sum = Sum + a(i, j) * x(j)Next jx(i) = a(i, n + 1) - SumNext iFor i = 1 To nPrint x( + Str(i) + )=; x(i)Next iEnd Sub例:已知方程組,求X1 X2 X3旳值。2X1+5X2+ X3=21 4X1+3X2+3X3=31 X1+3X2+2X3=16 4.3 三角分解法程序代碼:Private Sub Command1_Click()Dim a(), b(), l(), u(), x(), y()n = Val(InputBox(請輸入方程個數(shù)N:)ReDim a(n, n), b(n
22、), l(n, n), u(n, n), x(n), y(n)For i = 1 To nFor j = 1 To na(i, j) = Val(InputBox(請輸入系數(shù)矩陣A( + Str(i) + , + Str(j) + ):)Next jb(i) = Val(InputBox(請輸入右端常數(shù)項B( + Str(i) + ):)Next iFor i = 1 To nFor j = 1 To nIf i j ThenSum = 0For k = 1 To j - 1Sum = Sum + l(i, k) * u(k, j)Next kl(i, j) = (a(i, j) - Sum)
23、 / u(j, j)ElseSum = 0For k = 1 To i - 1Sum = Sum + l(i, k) * u(k, j)Next ku(i, j) = a(i, j) - SumEnd IfNext jNext iFor i = 1 To nSum = 0For j = 1 To i - 1Sum = Sum + l(i, j) * y(j)Next jy(i) = b(i) - SumNext iFor i = n To 1 Step -1Sum = 0For j = i + 1 To nSum = Sum + u(i, j) * x(j)Next jx(i) = (y(i)
24、 - Sum) / u(i, i)Next iFor i = 1 To nPrint x( + Str(i) + )=; x(i)Next iEnd Sub例:已知方程組,求X1 X2 X3旳值。2X1+3X2+4X3=38 X1+7X2+3X3=65 5X1+2X2+ X3=33 4.4 雅可比迭代法程序代碼:Dim a(), b(), x0(), x()n = Val(InputBox(請輸入方程個數(shù)N:)ReDim a(n, n), b(n), x0(n), x(n)ep = Val(InputBox(請輸入誤差限EP:)nmax = Val(InputBox(請輸入最大迭代次數(shù)Nmax
25、:)For i = 1 To nFor j = 1 To na(i, j) = Val(InputBox(請輸入系數(shù)矩陣A( + Str(i) + , + Str(j) + ):)Next jb(i) = Val(InputBox(請輸入右端常數(shù)項B( + Str(i) + ):)Next iFor i = 1 To nx0(i) = Val(InputBox(請輸入初始解X0( + Str(i) + ):)Next ik = 0f = 0While f = 0Max = 0For i = 1 To nSum = 0For j = 1 To nSum = Sum + a(i, j) * x0(
26、j)Next jd = (b(i) - Sum) / a(i, i)x(i) = x0(i) + dIf Max Abs(d) ThenMax = Abs(d)End IfNext ik = k + 1If Max nmax Then Print 迭代失敗 f = 1 Else For i = 1 To n x0(i) = x(i) Next i End IfEnd IfWendEnd Sub例:已知方程組,求X1 X2 X3 X4旳值。(ep=0.0001,最大迭代次數(shù)1000,初始值均為0)7X1+2X2+3X3+ X4=5 X1+5X2+2X3+ X4=42X1+ X2+8X3+3X4=
27、2 X1+4X2+ X3+7X4=74.5 高斯-賽德爾迭代法程序代碼:Private Sub Command1_Click()Dim a(), b(), x()n = Val(InputBox(請輸入方程個數(shù)N:)ep = 0.0001nmax = 10000ReDim a(n, n), b(n), x(n)For i = 1 To nFor j = 1 To na(i, j) = Val(InputBox(請輸入系數(shù)矩陣A( + Str(i) + , + Str(j) + ):)Next jb(i) = Val(InputBox(請輸入右端常數(shù)項b(: + Str(i) + ):)Next iFor i = 1 To nx(i) = Val(InputBox(請輸入初始解X(: + Str(i) + ):)Next ik = 0f = 0While f = 0Max = 0For i = 1 To nSum = 0For j = 1 To nSum = Sum + a(i, j) * x(j)Next jd = (b(i) - Sum) / a(i, i)x(i) = x(i) + dIf Max Abs(d) ThenMax = Abs(d)End IfNext ik = k + 1If Max nmax ThenPrint 迭代失敗f = 1End IfEnd I
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2022幼兒園督導(dǎo)工作計劃
- 如何保護(hù)患者合法權(quán)益、知情同意及告知制度相關(guān)知識培訓(xùn)課件
- 兄弟結(jié)婚祝福語15篇
- 密切內(nèi)部關(guān)系方面存在的問題集合6篇
- 2023班干部個人述職報告范文(10篇)
- 數(shù)學(xué)高三工作計劃
- 2025美容院轉(zhuǎn)讓合同范本美容院轉(zhuǎn)讓合同書
- 會計學(xué)生實習(xí)報告模板集合五篇
- 2024年離婚登記法律服務(wù)合同
- 2025項目分包的合同范本
- 2024年攝影協(xié)會工作計劃(3篇)
- 檔案管理制度
- 《客艙安全管理與應(yīng)急處置》課件-第7講 非法干擾行為
- 全國計算機等級考試一級試題及答案(5套)
- 醫(yī)生四頁簡歷10模版
- 律師行業(yè)職業(yè)操守與違紀(jì)警示發(fā)言稿
- 配電柜、配電箱技術(shù)規(guī)格書
- 靜脈治療護(hù)理技術(shù)操作標(biāo)準(zhǔn)解讀
- 云倉協(xié)議合同模板
- 湖北省鄂東南省級示范高中教育教學(xué)改革聯(lián)盟2024-2025學(xué)年高三上學(xué)期期中考試物理試題(無答案)
- 大學(xué)英語(基礎(chǔ))一學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
評論
0/150
提交評論