1、vb习题第一题Dim root(10) As VariantPrivate Sub Form_Load()Dim eps As Single: Dim h As SingleDim aa As Integer: Dim bb As IntegerDim m As Integer: Dim n As IntegerDim i As Integer: Dim p As Singleeps = 0.0000001: h = 0.1m = 6: aa = 0: bb = 2Call rt(aa, bb, h, m, n, eps)For i = 1 To n p = Round(root(i), 6)
2、 Debug.Print x; i; =; p Debug.Print x; i + 2; =; -p Next iEnd SubFunction f(x) As Double f = x 6 - 5 * x 4 + 6 * x - 1End FunctionSub rt(aa, bb, h, m, n, eps) n = 0 Dim a As Double: Dim b As Double Dim fa As Double: Dim fb As Double Dim c As Double: Dim fc As Double Dim delta As Double a = aa: fa =
3、f(a) Do b = a + h: fb = f(b) c = 0.5 * (a + b) fc = f(c) delta = Abs(b - c) If fc * fa 0 Then b = c Else: a = c: fa = fc End If Loop Until delta bb Or n = mEnd Sub结果:X1 = .167316X2 = 1.104632X3= -.167316X4=-1.104632第二题 Private Sub Form_Load() Dim kwji As Integer a(0, 0) = 1.502: a(0, 1) = 0.0514: a(
4、0, 2) = 0: a(0, 3) = 0.0408 a(1, 0) = 0.0261: a(1, 1) = 1.1516: a(1, 2) = 0: a(1, 3) = 0.082 a(2, 0) = 0.0342: a(2, 1) = 0.0355: a(2, 2) = 2.532: a(2, 3) = 0.2933 a(3, 0) = 0.034: a(3, 1) = 0.0684: a(3, 2) = 0: a(3, 3) = 0.0347 b(0) = 0.1013: b(1) = 0.09943: b(2) = 0.2194: b(3) = 0.03396 kwji = 0 Ca
5、ll SubMain(4, 0.0000000001) For i = 0 To 3 Debug.Print b(i) Next i End SubPublic Sub SubMain(n As Integer, ep As Double)Dim k As Integer For i = 0 To 99 m1(i) = i + 1 Next i For k = 0 To n - 1 Call cpe(n, k, ep) If p ep Then For j = k + 1 To n - 1 a(k, j) = a(k, j) / a(k, k) Next j b(k) = b(k) / a(k
6、, k) For i = 0 To n - 1 If (i k) Then For j = k + 1 To n - 1 a(i, j) = a(i, j) - a(i, k) * a(k, j) Next j b(i) = b(i) - a(i, k) * b(k) End If Next i Else kwji = 1 End If Next k For k = 0 To n - 1 a(0, m1(k) - 1) = b(k) Next k For k = 0 To n - 1 b(k) = a(0, k) Next kEnd SubPublic Sub cpe(n As Integer
7、, k As Integer, ep As Double) Dim tt As Double Dim i As Integer, j As Integer, i0 As Integer, j0 As Integer p = Abs(a(k, k) i0 = k j0 = k For i = k To n - 1 For j = k To n - 1 If (Abs(a(i, j) p) Then p = Abs(a(i, j) i0 = i j0 = j End If Next j Next i If (p ep) Then If (j0 k) Then For i = 0 To n - 1
8、tt = a(i, j0) a(i, j0) = a(i, k) a(i, k) = tt Next i tt = m1(k) m1(k) = m1(j0) m1(j0) = tt End If If (i0 k) Then For j = k To n - 1 tt = a(i0, j) a(i0, j) = a(k, j) a(k, j) = tt Next j tt = b(i0) b(i0) = b(k) b(k) = tt End If End IfEnd Sub结果:b(0) =6.265669 E-2 b(1)= 7.950508 E-2 b(2)= .0758797 b(3)
9、= 7.605627 E-2第三题:Private Sub Form_Load()Dim m As Integer, n As Integerm = 3: n = 60Dim y(2, 60) As Single, yy(2, 60) As SingleDim h As Integer, i As Integer, j As IntegerDim l As Integer, d As IntegerDim x(60) As Single, s(3) As SingleDim k(2, 4) As Single, p As Singleh = 1y(0, 0) = 0.01: y(1, 0) =
10、 0: y(2, 0) = 0s(0) = 0: s(1) = 0.5: s(2) = 0.5: s(3) = 1For l = 1 To n Debug.Print t=; l For i = 1 To m For j = 1 To 4 p = x(l - 1) + s(j - 1) * h For d = 1 To m yy(d - 1, l - 1) = y(d - 1, l - 1) + s(j - 1) * k(d - 1, j - 1) Next d Select Case i Case 1 k(i - 1, j) = -h * (0.0044 + 0.0021) * yy(0,
11、l - 1) Case 2 k(i - 1, j) = h * (0.0044 * yy(0, l - 1) - 2.96 * yy(1, l - 1) Case 3 k(i - 1, j) = h * (2.96 * yy(1, l - 1) + 0.0021 * yy(0, l - 1) End Select Next j x(l) = p y(i - 1, l) = y(i - 1, l - 1) + 1 / 6 * (k(i - 1, 1) + 2 * k(i - 1, 2) + 2 * k(i - 1, 3) + k(i - 1, 3) + k(i - 1, 4) Debug.Pri
12、nt c(; i; )=; y(i - 1, 1), Next i Debug.PrintNext lEnd Subt= 1 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 2 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 3 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 4 c( 1 )= 9.924413E-03 c( 2 )= 8.03
13、3664E-06 c( 3 )= 6.755378E-05 t= 5 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 6 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 7 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 8 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-0
14、5 t= 9 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 10 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 11 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 12 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 13 c( 1 )= 9.924413E
15、-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 14 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 15 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 16 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 17 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06
16、 c( 3 )= 6.755378E-05 t= 18 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 19 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 20 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 21 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t=
17、 22 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 23 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 24 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 25 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 26 c( 1 )= 9.924413E-03
18、 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 27 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 28 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 29 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 30 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c(
19、 3 )= 6.755378E-05 t= 31 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 32 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 33 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 34 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 35
20、 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 36 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 37 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 38 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 39 c( 1 )= 9.924413E-03 c(
21、 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 40 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 41 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 42 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 43 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3
22、)= 6.755378E-05 t= 44 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 45 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 46 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 47 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 48 c(
23、 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 49 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 50 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 51 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 52 c( 1 )= 9.924413E-03 c( 2
24、)= 8.033664E-06 c( 3 )= 6.755378E-05 t= 53 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 54 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 55 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 56 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )=
25、6.755378E-05 t= 57 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 58 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 59 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 t= 60 c( 1 )= 9.924413E-03 c( 2 )= 8.033664E-06 c( 3 )= 6.755378E-05 第四题第一小题Publ
26、ic a As DoublePublic b As DoublePublic r As DoubleDim ya(0 To 13) As DoubleDim xa(0 To 13) As DoublePrivate Sub Form_Load() Dim I As Integer Dim r0 As Double Dim C(3) As Double ya(0) = 4896: ya(1) = 4886: ya(2) = 4875: ya(3) = 4865: ya(4) = 4855: ya(5) = 4845: ya(6) = 4834 ya(7) = 4824: ya(8) = 4804
27、: ya(9) = 4783: ya(10) = 4742: ya(11) = 4701: ya(12) = 4599: ya(13) = 4496 xa(0) = 5: xa(1) = 10: xa(2) = 15: xa(3) = 20: xa(4) = 25: xa(5) = 30: xa(6) = 35 xa(7) = 40: xa(8) = 50: xa(9) = 60: xa(10) = 80: xa(11) = 100: xa(12) = 150: xa(13) = 200 Call Listq1(14) Debug.Print a Debug.Print b Debug.Pri
28、nt r End SubPublic Function Listq1(m As Integer) Dim X1, Y1, X2, Y2, XY, LXY, LYY, LXX As Double Dim I, J As Integer X1 = Y1 = X2 = Y2 = XY = 0 For I = 0 To m - 1 X1 = X1 + xa(I): X2 = X2 + xa(I) * xa(I) Y1 = Y1 + ya(I): Y2 = Y2 + ya(I) * ya(I) XY = XY + xa(I) * ya(I) Next I LXX = X2 - X1 * X1 / m:
29、LYY = Y2 - Y1 * Y1 / m: LXY = XY - X1 * Y1 / m b = LXY / LXX: a = (Y1 - b * X1) / m: r = LXY / Sqr(-LXY * LYY) End Function结果:4906.14584040747 -2.05005093378608 0.99841971516073542Dim m, n As IntegerDim ax, a(7) As DoubleDim i, j, k As IntegerDim s(14), t(7), b(7, 8) As DoubleDim y(0 To 13) As Doubl
30、eDim x(0 To 13) As DoubleDim m1 As Double, mm As DoublePrivate Sub Form_Load() Dim i As Integer Dim r0 As Double Dim C(3) As Double m = 14: n = 7 y(0) = 4896: y(1) = 4886: y(2) = 4875: y(3) = 4865: y(4) = 4855: y(5) = 4845: y(6) = 4834 y(7) = 4824: y(8) = 4804: y(9) = 4783: y(10) = 4742: y(11) = 4701: y(12) = 4599: y(13) = 4496 x(0) = 5: x(1) = 10: x(2) = 15: x(3) = 20: x(4) = 25: x(5) = 30: x(6) = 35 x(7) = 40: x(8) = 50: x(9) = 60: x(10)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1