ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

EXCEL VBA¨D¤@¤¸¤G¦¸¤èµ{¦¡ (¤£¥Î¤½¦¡¸Ñ)(2)

¥»©«³Ì«á¥Ñ ML089 ©ó 2021-10-26 08:40 ½s¿è

¦^´_ 9# Andy2483
¬P´Á¤é¥hÅSÀç¡A¬P´Á¤@±ß¤W¦^®a¡A¬Ý¨ì§Aªºµ{¦¡¸Ñ¤@¤¸¥|¦¸¡A®M¨ì§Ú­ì¥ýªºµ{¦¡¨S¦³¿ìªk§¹¦¨¸Ñ¥X¡A¤£§¹µ½¦a¤è«Ü¦h¡C
¥»¨ÓÅSÀç¦^¨Ó«Ü²ÖÀ³­n¦­ºÎªº«o¤SºÎ¤£µÛ¡A­«·s­×¥¿¤@¤U­ì¥ýµ{¦¡¡A²×©ó§¹¦¨¥i¥HºÎı¤F¡C
1 ¤j°Ï¶¡ -10000 ~ 10000 ¬d¸ß­n§Ö¡A±N ¬d¸ß Step ¤À¬° ¤j¡B¤¤¡B¤p(¥iÅÜ) ¡Aªì©l s = 100¡A¹J¨ì²Ä¤@¸Ñ«á §ï¬° s = s1 = 0.1¡A·í¸Ñ¦b°Ï¶¡(x ~ x+s)®É¦A²Ó¤À s/ss¡Ass=10³£¥i¥H¡C¥[³t¬d¸ß
   ¸Ñµª§¹4¦¸¸Ñ´N¥i¥H¸õÂ÷°j°é¡A¥[³t¬d¸ß
  ³o¦¸Àu¤Æ­pºâ°j°é¥Ñ 20800¦¸­°¦Ü 500¦¸¥ª¥k
2 ¦³ªñ¦ü¸Ñ®É¡A¦A¥Hf( round(x,12) )Àˬd­×¥¿¬°¯u¹ê¸Ñ¡C
3 Áٯʤ֧Aªº¤Íµ½¤H¾÷¤¶­±¡A³o¬P´Á¦A¨Ó·Q¤@·Q¡C

Function f(x)
    'f = x ^ 2 + 2 * x - 4
    'f = x ^ 4 - 6 * x ^ 3 + x ^ 2 + 2 * x + 24
    f = 2 * x ^ 4 - 4 * x ^ 3 - 3 * x ^ 2 + 7 * x - 2  '¤H¤u¶ñ¤J¤èµ{¦¡
End Function
Sub ¤@¤¸¤èµ{¦¡¼É¤O¸Ñªk_ML089()
    Dim r, c1, c2, n, x, x2, s, s1, ss, ct, tm, xNo, xN
    tm = Timer
    ThisWorkbook.Sheets.Add(After:=Worksheets(1)).Name = Format(Now(), "dd_hhmmss") '
    x1 = -10000: x2 = 10000: x = x1 '¬d¸ß°Ï¶¡
    s = 100: s1 = 0.1: ss = 10:  'Step ªì©l­È¨Ï¥Îs,§ä¸Ñ1°Ï¶¡«á¨Ï¥Îs1¡Ass°Ï¶¡²Ó¤À°£¼Æ
    xNo = 4: xN = 0 '¤@¤¸´X¦¸ : ­p¦¸
   
    r = 3: c1 = 1: c2 = 2 'cells ¦ì¸m
    'Cells(r, c1).Resize(, 3) = Array("x1", "x2", "f(x1)")
    While x <= x2
        'DoEvents '·|¼W¥[­pºâ®É¶¡
        ct = ct + 1 '´`Àô¦¸¼Æ
        If Application.Median(f(x), 0, f(x + s)) = 0 Then '¸Ñµª¬O§_¦bx»Px+s¤§¶¡
            'r = r + 1: Cells(r, c1).Resize(, 3) = Array(x, x + s, f(x)) 'Debug ¥Î
            If Round(f(x), 12) = 0 Then 'ºë«×¤p¼Æ12¦ì¼Æ¬°0®É¬°ªñ¦ü¸Ñ
                xN = xN + 1: r = r + 1
                ANS = "ªñ¦ü¸Ñ¡GX" & xN & " = "
                If f(Round(x, 12)) = 0 Then '¯u¹ê¸Ñ§PÂ_»P­×¥¿
                    x = Round(x, 12)
                    ANS = "¯u¹ê¸Ñ¡GX" & xN & " = "
                End If
                Cells(r, c1) = ANS & x & " ,f(x) = " & f(x)
                If xN = xNo Then GoTo 999 '¸Ñµª§¹¦¨¸õ¥X°j°é
                x = x + s
                s = s1
            Else
                s = s / ss '¥Ø«ex~x+s°Ï¶¡¡As¦A²Ó¤À1/SS­¿
            End If
        Else
            x = x + s
        End If
    Wend
999:
    Cells(r + 1, c1) = "¬d¸ß°Ï¶¡¡G" & x1 & "    " & x2
    Cells(r + 2, c1) = "Step ªì©l­È¤Î²Ó¤À°£¼Æ¡G" & s1 & "    " & ss
    Cells(r + 3, c1) = "´`Àô¦¸¼Æ¡G" & ct
    Cells(r + 4, c1) = "­pºâ®É¶¡¡G" & Format(Timer - tm, "0.000")
End Sub

'¥i¥H§R°£¤é´ú¸Õ¤u§@ªí
Sub Del_Sheet()
    Dim MyBook As Workbook, sh As Worksheet
    Set MyBook = ThisWorkbook
    Application.DisplayAlerts = False  '°±¤î¨t²ÎªºÄµ¥Ü
    For Each sh In MyBook.Sheets
        If sh.Name Like Day(Now()) & "_*" Then sh.Delete '§R°£·í¤é DD_*
    Next
    Application.DisplayAlerts = True   '«ì´_¨t²ÎªºÄµ¥Ü
End Sub
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 11# ML089


    «e½ú±Ð®v¸`§Ö¼Ö
¦V±z¹Dºp sorry¡G
10¼Ó¤§«á¦£·sªº®×¥ó¡A¦nªø¤@¬q®É¶¡¨S¤W½×¾Â¾Ç²ß¡A«e´X¤Ñ¾Ç²ßFunction ()¤~¬Ý¨ì11¼Óªº«e½ú«ü¾É¦^ÂСA¤ßùؤ@ª½¹L·N¤£¥h¡A¶X¤µ¤Ñ±Ð®v¸`¦V«e½ú¦^ÂСA¨Ã¯¬«e½ú ±Ð®v¸`§Ö¼Ö

TOP

        ÀR«ä¦Û¦b : ¬O«D·í±Ð¨|¡AÆg¬ü§@ĵ±§¡C
ªð¦^¦Cªí ¤W¤@¥DÃD