2017年12月12日 星期二

[ VB2010 ] 疊代運算法求平方根.利用公式x(n+1)=1/2*(x(n)+a/x

疊代運算法求平方根.利用公式x(n+1)=1/2*(x(n)+a/x



Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x1, x2, x3 As Double
        x2 = 1.0
        x3 = Val(TextBox1.Text)
        TextBox2.Text = ""

        Do Until Math.Abs(x2 - x1) < 0.01
            x1 = x2
            x2 = 0.5 * (x1 + x3 / x1)
        Loop

        TextBox2.Text &= x2.ToString("###.#####") & vbCrLf
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

沒有留言:

張貼留言

Node-Red & ModeBus FC=1

Node-Red & ModeBus FC=1 write address=0..7   8bits read address=16..23 8bits  [{"id":"cf7c1253d4d997dd","type&q...