Hello. I am also trying to write a program that performs this equation: (f(X) = aX3 + bX2 + cX + d). I am so completely lost, but so far I have this:
- Public Class Form1
-
-
Private Sub btncalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalc.Click
-
Dim A As Double
-
Dim B As Double
-
Dim C As Double
-
Dim D As Double
-
Dim X As New Double
-
Dim I As Integer = 0
-
Dim Err As Decimal
-
Dim intCount As Integer = 0
-
Dim Formula As String = ((A * X ^ 3) + (B * X ^ 2) + (C * X + D)) / ((3 * A * X ^ 2) + (2 * B * X + C))
-
-
txtA.Text = A
-
txtB.Text = B
-
txtC.Text = C
-
txtD.Text = D
-
-
-
-
If Formula < Err Then
-
-
Else
-
Do While Formula >= Err
-
-
intCount += 1
-
-
Loop
-
lblroot.Text = Formula
-
End If
-
End Sub
-
End Class
-
I have inputs for A,B,C,D and an error limit. I'm trying to get the program to display the root (X), and the number of times it goes through the loop (the number of iterations).
1.a, b, c, and d are four constants that define the equation as shown at the top of the screen image above;
X is the root of the equation;
E is an error limit, typically very small (e.g., 0.000001);
f(X) = aX3 + bX2 + cX + d;
f’(X) = 3aX2 + 2bX + c;
2.Call Xi the current estimate of X, Xi-1 the previous estimate, and Xi+1 the next (improved) estimate of X.
3.If the absolute value of Xi – Xi-1 is less than E you are done.
4.If the absolute value of Xi – Xi-1 is greater than or equal to E, then:
a.Xi-1 = Xi;
b.Xi+1 = Xi – f(Xi) / f’(Xi)
c.Xi = Xi+1
d.go back to step 3.