Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
METHOD
ID Number:
Lab Section:
Objectives
1. To determine roots of an equation in single variable using Newton-Raphson method.
2. To understand the MATLAB implementation of the Newton-Raphson method.
3. To analyze of results using different initial values and error tolerance.
Algorithm
Assuming the function f(x) is differentiable, a tangent of the function of xi, f’(xi) is extrapolated
down to the x- axis to provide an estimate of the root xi+1 as shown by figure 2.
From the Figure, the Newton’s updating formula can be written as:
1
From the above formula, an initial value is needed. The choice of the initial value will affect the
convergence of the solution.
Termination Criteria:
where 𝑥𝑖+1 is the root of current (new) iteration and 𝑥𝑖 is the root of previous (old) iteration. The
notation 𝜀𝑎,𝑖+1(%) represents the error for current estimate of the root (𝑥𝑖+1).
Then the computations will be terminated if
Pseudocode
FUNCTION NewtRaph(x0, es, imax)
i = 1
xi = x0
eai = ∞
DO
xi+1 = xi – f(xi)/f’(xi)
IF xi+1 ≠ 0 THEN
eai+1 = ABS((xi+1 – xi)/xi+1)*100
END IF
DISPLAY i, xi, f(xi), f’(xi), eai
IF eai < es OR iter ≥ imax EXIT
i = i + 1
END DO
NewtRaph = xi
END NewtRaph
2
Practical Work
Lab Work
1. Write a MATLAB function y = func2(x) which implements the equation f(x) = x3 – 2x2 −
6x + 4 = 0. It will be used by the Newton-Raphson method.
2. Write a MATLAB function y = dfunc2(x) which implements the derivative of the equation
f(x) = x3 – 2x2 − 6x + 4 = 0. It will be used by the Newton-Raphson method.
3
3. Implement the Newton-Raphson method in MATLAB using the given pseudocode.
4
4. Use the MATLAB implementation of Newton-Raphson method to find a root of the
function f(x) = x3 – 2x2 − 6x + 4 = 0. with the initial guess x0 = 3.0. Perform the
computations until percentage approximate relative error (ℇa (%)) is less than ℇs = 2%. You
are required to fill the following table.
5. Repeat step 4 until percentage approximate relative error (ℇa (%)) is less than ℇs = 0.2%.
0
1
2
3
4
0
1
2
3
4
5
6
7
5
Discussion and Analysis
1. How does the choice of the initial guess affect the solution?
3. How the speed of convergence and the error tolerance (s) are related?