0% found this document useful (0 votes)
36 views10 pages

Secant Method Research Paper

The document describes using the secant method to find the roots of the equation 2x^4 + 5x^3 + 2x^2 + 7x + 10 with a tolerance of 0.001. It provides the methodology which includes defining the equation, setting initial guesses for x1 and x2, calculating subsequent x values using the secant method formula, and iterating until the relative error is less than the tolerance. A Microsoft Excel VBA macro is presented that implements this methodology to calculate the roots. The results are the roots -2.31863 and -1.19872 found within the specified tolerance.

Uploaded by

ashketch069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views10 pages

Secant Method Research Paper

The document describes using the secant method to find the roots of the equation 2x^4 + 5x^3 + 2x^2 + 7x + 10 with a tolerance of 0.001. It provides the methodology which includes defining the equation, setting initial guesses for x1 and x2, calculating subsequent x values using the secant method formula, and iterating until the relative error is less than the tolerance. A Microsoft Excel VBA macro is presented that implements this methodology to calculate the roots. The results are the roots -2.31863 and -1.19872 found within the specified tolerance.

Uploaded by

ashketch069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

I.

INTRODUCTION

A secant method is an open method in


locating the root of non-linear equations. This
method may also be used in determining the root of
a scalar-valued function f(x) of a single variable.
Similar to the Regula-falsi method in many aspects,
but it trades the risk of non-convergence for speedier
convergence. It requires two initial guesses (X1 and
X2) that do not necessarily bracket the root and may be on either side of the solution.
The value of X3 may be solved using a particular equation and in the next iteration,
X2 and X3 will be considered to be the new X1 and X2.

The secant method formula follows:

x3 = x2 − f(x2)(x1−x2)
f(x1)−f(x2)

II. Problem Statement

Using the bisection method, find the roots of the equation 2x4+5x3+2x2+7x+10
when the tolerance is about 0.001.

III. METHODOLOGY

The algorithm follows this methodology in creating a Microsoft Excel script to


find the roots of f(x) = 2x4+5x3+2x2+7x+10 with a tolerance value 0.001.

1. Start.

2. Define the equation f(x).

3.Set initial values for X1 and X2


4. Enter any value for the initial guesses that their f(X1) and f(X2) values result
too less than zero when multiplied. If not, then go back to the previous step.

5. Find the X3 using the formula:

X3 = X2 –( f(X2)(X1-X2)/(f(X1) - f(X2)))

6. Evaluate the Relative Error using the formula

Relative Error = ((X3-X2)/X3)

7. Print X3 as the root of the solution then repeat step 6 until the error becomes
smaller than the specified criterion.

8. End

IV. Microsoft Excel Script

The following code is used to find the roots of the equation f(x) =
2x4+5x3+2x2+7x+10. The code will ask the user to set two guesses and it will iterate
the value using Secant method to find the roots. The code can be modified allowing
the user to change the tolerance value requirements. This code utilizes the Microsoft
Excel VBA programming language feature and it runs using the Macros feature in
Microsoft.

Sub SecantMethodWithIterations()

Dim x1 As Double, x2 As Double, x3 As Double

Dim fx1 As Double, fx2 As Double, fx3 As Double

Dim tolerance As Double, ea As Double

Dim maxIterations As Integer

Dim i As Integer

' Prompt the user for the initial guesses'

On Error Resume Next

x1 = InputBox("Enter the initial guess x1:", "Initial Guess x1")


If Not IsNumeric(x1) Then

MsgBox "Invalid input. Please enter a numeric value for the initial guess x1."

Exit Sub

End If

x2 = InputBox("Enter the initial guess x2:", "Initial Guess x2")

If Not IsNumeric(x2) Then

MsgBox "Invalid input. Please enter a numeric value for the initial guess x2."

Exit Sub

End If

' Prompt the user for the tolerance'

On Error Resume Next

tolerance = InputBox("Enter the tolerance:", "Tolerance")

If Not IsNumeric(tolerance) Then

MsgBox "Invalid input. Please enter a numeric value for the tolerance."

Exit Sub

End If

On Error GoTo 0

' Maximum number of iterations (adjust as needed)'

maxIterations = 1000

' Clear previous results'

Cells.ClearContents

' Set headers'

Cells(1, 1).Value = "Iteration"

Cells(1, 2).Value = "x1"

Cells(1, 3).Value = "x2"

Cells(1, 4).Value = "fx1"

Cells(1, 5).Value = "fx2"

Cells(1, 6).Value = "x3"


Cells(1, 7).Value = "fx3"

Cells(1, 8).Value = "ea(%)" ' Display new column for ea(%)

' Initialize ea with a large value'

ea = 100

' Loop for a maximum number of iterations'

For i = 1 To maxIterations

' Calculate function values at x1 and x2'

fx1 = 2 * x1 ^ 4 + 5 * x1 ^ 3 + 2 * x1 ^ 2 + 7 * x1 + 10

fx2 = 2 * x2 ^ 4 + 5 * x2 ^ 3 + 2 * x2 ^ 2 + 7 * x2 + 10

' Calculate the new estimate x3 using the Secant method'

x3 = x2 - fx2 * (x1 - x2) / (fx1 - fx2)

fx3 = 2 * x3 ^ 4 + 5 * x3 ^ 3 + 2 * x3 ^ 2 + 7 * x3 + 10

' Calculate approximate error ea'

If i > 1 Then

ea = Abs((x3 - x2) / x3) * 100

End If

' Display values in the current iteration'

Cells(i + 1, 1).Value = i

Cells(i + 1, 2).Value = x1

Cells(i + 1, 3).Value = x2

Cells(i + 1, 4).Value = fx1

Cells(i + 1, 5).Value = fx2

Cells(i + 1, 6).Value = x3

Cells(i + 1, 7).Value = fx3

Cells(i + 1, 8).Value = ea

' Check for convergence'

If Abs(ea) < tolerance Then


Cells(1, 10).Value = "Root:"

Cells(2, 10).Value = x3

Cells(4, 10).Value = "No. of Iterations:"

Cells(5, 10).Value = i

Cells(7, 10).Value = "Tolerance:"

Cells(8, 10).Value = tolerance

Exit For

End If

' Update x1, x2, and x3 for the next iteration'

x1 = x2

x2 = x3

Next i

' Display an error message if the maximum number of iterations is reached'

If i > maxIterations Then

MsgBox "You have reached the maximum number of iterations. Try another value!"

End If

End Sub
V. ALGORITHM FLOW CHART
V. RESULTS

Using the Macros feature in MS Excel, the feature will run the program. The program
will ask for the value of the x1, x2, and tolerance. It will automatically calculate and iterate the
procedure until it reaches the tolerance value and stops. If the maximum number of iterations
is reached without finding the root, it displays an error message. This program is a practical
tool for solving mathematical problems using Excel.
Therefore, the root of the function f(x) = 2x4+5x3+2x2+7x+10 with a tolerance value of
0.001 is -2.31863 and -1.19872.

References:

https://www.geeksforgeeks.org/program-to-find-root-of-an-equations-using-secant-
method/

https://www.codesansar.com/numerical-methods/secant-method-using-c-
programming.htm

You might also like