Numerical Calculation Part 1: Equations &Roots (Newton- Raphson's Method) Dr.Entesar Ganash Solving equations A numerical method is an approximate computer method to solve a mathematical problem that often can not be solved analytically. If we want to Solve the equation f(x)=0 that means we want to find its root x (or roots) depends on the equation degree. E.g. Function: f(x) = x2 - 4 Roots: x = -2, x = 2 Because: f(-2) = (-2)2 - 4 = 4 - 4 = 0 f(2) = (2)2 - 4 = 4 - 4 = 0 For any f(x), there is no general technique to obtain roots analytically. Here we study two numerical method for finding roots numerically. Newton's Method Bisection's Method Newton's Method A general idea: may be it is the easiest numerical method to apply for solving equations, i.e. Newton’s method could be used to solve a general equation f(x)=0. it is an iterative method, i.e. it repeatedly attempts to improve a root estimation. If is an approximation to root, the next approximation is given as the following: Where is the first derivative of , until has come close enough to zero. It converges to a root only if the starting guess is ‘close enough’. since ‘close enough’ depends on the nature of A Structure Plan: A structure plan to execute Newton's method: 1. Read the starting value (initial guess) of x and required accuracy (Epsilon) 2. Define the function 3. test whether 4. If the condition in step 3 is right repeat until the condition in step 3 becomes Wrong (that means Newton converged ) or up to k=20 (for example , and it is necessary to limit k because the process may not converge) , find a new value of x from Newton's method i.e. using print and and its derivative , end a program. Example Write a program using Newton’s method to solve this equation starting with x= 2 and stopping either when the absolute value of the function is less than or after 20 repetitions. Solving PROGRAM NEWTON IMPLICIT NONE Integer::k ! a counter Real :: Eps ,x ! required accuracy (epsilon) & staring guess k=0 Eps=1.0E-6 x=2 write(*,*)' ','x',' ', 'f(x)' write(*,*)'----------------------------------' Do WHILE ((ABS(f(x))>=Eps) .AND. (k< 20)) x=x-f(x)/df(x) write(*,*)x, f(x) k=k+1 END DO IF (ABS(f(x))<=Eps)THEN Write(*,*)'Newton converged' ELSE Write(*,*)'Newton diverged' END IF Contains !-------------------------!Function Subprogram f is to solve f(x)=0 !-------------------------Real function f(x) Implicit none Real:: f,x f=x**3+x-3 End function f !-------------------------! Anther Function Subprogram df !-------------------------Real function df(x) Implicit none Real::df,x df=3*x**2+1 End function df !-------------------------END PROGRAM NEWTON continue Solving 1 2 The result: References •Hahn, B.D., 1994, Fortran 90 For Scientists and Engineers, Elsevier. •http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html •Univ.,
© Copyright 2026 Paperzz