EXCEL VBA¨D¤@¤¸¤G¦¸¤èµ{¦¡ (¤£¥Î¤½¦¡¸Ñ)(2)
- ©«¤l
- 8
- ¥DÃD
- 6
- ºëµØ
- 0
- ¿n¤À
- 27
- ÂI¦W
- 0
- §@·~¨t²Î
- WIN10
- ³nÅ骩¥»
- Office 2016
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2021-10-18
- ³Ì«áµn¿ý
- 2021-12-22
|
¦^´_ 2# Andy2483
«e½ú±z¦n ¥i¥Hµy·L²³æ»¡©ú¤@¤U¨C¶µ¥Nªíªº·N¸q¶Ü
³o¦ê¥H¤U¦n¹³¬O¤½¦¡ ³]©w³o¦êªº¥Î·N¬O¤°»ò (4 * a * c - b ^ 2) / 4 * a = 0 (¦pªG¤£¯à¥Î¤½¦¡¸Ñ¬O§_¥i¥H¤£³]©w¦¹¶µ)
If n = 2 Then
If (4 * a * c - b ^ 2) / 4 * a = 0 Then
MsgBox "°ß¤@¸Ñ X= " & (-b) / (2 * a): Exit Sub
ElseIf ((4 * a * c - b ^ 2) / 4 * a > 0 And a > 0) Or ((4 * a * c - b ^ 2) / 4 * a < 0 And a < 0) Then
MsgBox " X µL¸Ñ!": Exit Sub
½Ð«e½úµy·L»¡©ú¤@¤U
888 ©M999©M S0¤ÎS0 =-100*J©MS1©M S1 =100*J ¬O¤°»ò
ÁÙ¦³¥H¤Uªº³]©w»¡©ú ·Q¤F¸Ñ¸Ô²Ó
End If
888: S0 = -100 * J: S1 = 100 * J: S = J: P = 1
999
For X = S0 To S1 Step S
Y0 = a * X ^ n + b * X + c
Y1 = (a * (X + S)) ^ n + (b * (X + S)) + c
P = Y0 * Y1
If (S < 10 ^ -13 And J = 1) Or (S > -(10 ^ -13) And J = -1) Then P = 0
If P = 0 Then
If c = 0 And J = 1 Then X1 = X
If c = 0 And J = -1 Then X2 = X
If J = -1 Then: MsgBox "X1= " & X1 & vbLf & vbLf & "X2= " & X2: Exit Sub
J = -1: GoTo 888
ElseIf P < 0 Then
S0 = X: S1 = S0 + S: S = S / 10 '
If J = 1 Then
MsgBox "X1 ¤¶©ó " & S0 & " ~ " & S1
X1 = S1
Else
MsgBox "X2 ¤¶©ó " & S0 & " ~ " & S1
X2 = S1
End If
GoTo 999
End If
Next
End Sub
¤Wzµ{¦¡¶]¥X¨Ó
X1=1.2360679774997¡AX2=-3.2360679774997
µª®×«á±¦n¹³ÁÙ¤Ö¤@¶µ¼Æ¦r
X1=1.23606797749979¡AX2=-3.23606797749979
µ{¦¡À³¸Ón«ç»ò§ï
·PÁ«e½ú |
|
|
|
|
|
|
- ©«¤l
- 1446
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1470
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-10-21
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2021-10-20 14:32 ½s¿è
¦^´_ 1# ´Ë³¥
°Ñ¦Ò
Option Explicit
Sub TEST()
Dim X, Y, a, b, c, n, U1, U2, u, v, S, S0, S1, Y0, Y1, X1, X2, P, J
J = 1: Y = a * X ^ n + b * X + c: a = 1: b = 2: c = -4: n = 2
If n = 2 Then
If (4 * a * c - b ^ 2) / 4 * a = 0 Then
MsgBox "°ß¤@¸Ñ X= " & (-b) / (2 * a): Exit Sub
ElseIf ((4 * a * c - b ^ 2) / 4 * a > 0 And a > 0) Or ((4 * a * c - b ^ 2) / 4 * a < 0 And a < 0) Then
MsgBox " X µL¸Ñ!": Exit Sub
End If
If b = 0 And c < 0 Then X1 = (-c / a) ^ 0.5: X2 = -(-c / a) ^ 0.5
End If
888: S0 = -100 * J: S1 = 100 * J: S = J: P = 1
999
For X = S0 To S1 Step S
Y0 = a * X ^ n + b * X + c
Y1 = (a * (X + S)) ^ n + (b * (X + S)) + c
P = Y0 * Y1
If (S < 10 ^ -13 And J = 1) Or (S > -(10 ^ -13) And J = -1) Then P = 0
If P = 0 Then
If c = 0 And J = 1 Then X1 = X
If c = 0 And J = -1 Then X2 = X
If J = -1 Then: MsgBox "X1= " & X1 & vbLf & vbLf & "X2= " & X2: Exit Sub
J = -1: GoTo 888
ElseIf P < 0 Then
S0 = X: S1 = S0 + S: S = S / 10 '
If J = 1 Then
MsgBox "X1 ¤¶©ó " & S0 & " ~ " & S1
X1 = S1
Else
MsgBox "X2 ¤¶©ó " & S0 & " ~ " & S1
X2 = S1
End If
GoTo 999
End If
Next
End Sub
End Sub |
|
|
|
|
|
|