Source code in Pascal:
Procedure Hord(A,B:Real; E:Real; var X, Fx:Real;n:integer); var X0,Fa,Fb:real; Begin if dF2(A,n)*F(A,n) > 0 then begin X:=B;X0:=A; Fa:=F(A,n); while (Abs(X0-X)>E) do begin X0:=X; Fx:=F(X0,n); X:=X0-Fx*(X0-A)/(Fx-Fa); end end else begin X:=A;X0:=B; Fb:=F(B,n); while (Abs(X0-X)>E) do begin X0:=X; Fx:=F(X0,n); X:=X0-Fx*(B-X0)/(Fb-Fx); end end; Fx:=F(X,n); End. Attempt to solve on VBA:
Dim x As Single, x1 As Single, f1 As Single, f2 As Single Dim n As Integer Const e = 0.001 Private Function f(ByVal x As Double) As Double f = x - 3 - Sin(3 * x) End Function Private Function Fd(ByVal x As Double) As Double Fd = 1 - 3 * Cos(3 * x) End Function Private Sub Command3_Click() 'metod hord Text3.Text = "" x1 = Val(Text1.Text) X2 = Val(Text2.Text) Do While Abs(x1 - X2) > e x3 = X2 - f(X2) * (X2 - x1) / (f(X2) - f(x1)) x1 = X2 X2 = x3 DoEvents Loop Text3.Text = Round(x3, 5) End Sub