1Chapter 1

Solutions of Equations in One Variable

1.1 Graphical Methods

A simple method for obtaining a root of the equation f(x) = 0 is to plot the function and observe where it crosses the x axis. There are many available software that will facilitate making a plot of a function. I will use Matlab exclusively for the course notes, however you can use another software such as Excel or Matcad for your work.

Example 1.1

Solve f(x) = (1  e0.15x)  50 = 0 using the graphical method.

Solution

The function f(x) = (1  e0.15x)  50 can be plotted in Figure 1.1 using the following Matlab statements.

% Graphical method to solve 600*(1-exp(-0.15x))/x - 50

%

x=4:.1:20;

fx=600*(1-exp(-.15*x))./x-50;

plot(x,fx,[0 20],[0 0])

xlabel('x');ylabel('f(x)')

grid;zoom on

Figure 1.1 The graphical method for roots finding.

The Matlab Zoom on statement allows the function to be zoomed in at the cursor with left mouse click ( right mouse click will zoom out). Each time you click, the axes limits will be changed by a factor of 2 (in or out). You can zoom in as many times as necessary for the desired accuracy. Figure 1.2 shows the approximate root x to be 8.79.

Figure 1.2 The graphical method for roots finding with Matlab Zoom on.

The plot of a function between x1 and x2 is important for understanding its behavior within this interval. More than one roots can occur within the interval when f(x1) and f(x2) are on opposite sides of the x axis. The roots can also occur within the interval when f(x1) and f(x2) are on the same sides of the x axis. Since the functions that are tangent to the x axis satisfy the requirement f(x) = 0 at this point, the tangent point is called a multiple root.

1.2 The Bisection Method

The bisection method or interval halving can be used to determine the solution to f(x) = 0 on an interval [x1 = a, x2 = b] if f(x) is real and continuous on the interval and f(x1) and f(x2) have opposite signs. We assume for simplicity that the root in this interval is unique. The location of the root is then calculated as lying at the midpoint of the subinterval within which the functions have opposite signs. The process is repeated to any specified accuracy. The procedure can be summarized in the following steps

Let f(x1) f(x2) < 0 on an interval [x1 = a, x2 = b]

Step 1Let xx = (x1 + x2); f1 = f(x1); f2 = f(x2)

Step 2Evaluate fx = f(xx)

If fxf1 > 0 then

x1 = xx; f1 = fx

else

x2 = xx; f2 = fx

Step 3If abs(x2 x1)> an error tolerance, go back to Step 1

Figure 1.3 The first three iterations x3, x4, and x5 of the bisection method.

Figure 1.3 shows first three iterations x3, x4, and x5 of the bisection method.

x3 = (x1 + x2) = (6 + 14) = 10

f(x1) f(x3) < 0 x4 = (x1 + x3) = (6 + 10) = 8

f(x3) f(x4) < 0 x5 = (x3 + x4) = (10 + 8) = 9

Since f(x1) and f(x2) bracket the root and x3 = (x1 + x2) = (a + b), the error after the first iteration is less than or equal to (b  a). Let x be theactual root of f(x) and xn be the approximate root after n iterations, then

| xn  x|

The above formula can be used to determine the number of iterations n required to find the root within a specified error. For example, if we want to find the root of f(x) with | xn  x| 10-3 within the interval (b  a) = 1 then the number of iterations n is determined from the following steps

| xn  x|

10-3=  2n = 103

n  = 9.97 = 10

We need 10 iterations to reduce the error to 10-3. A Matlab program for the bisection method is listed in Table 1.1 where the function f(x) is an input to the program. The statement eval(f) is used to evaluate the function at a given value of x.

Table 1.1 ______

% Bisection Method

f=input('f(x)=','s');

tol=input('error tolerance =1e-5, new tolerance=');

if length(tol)==0,tol=1e-5;end

x1=input(' First guess=');

x=x1;

f1=eval(f);

x2=input(' Second guess=');

x=x2;

f2=eval(f);

if f1*f2<0

for i=1:101

x=(x1+x2)/2;

fx=eval(f);

if fx*f1>0

x1=x;f1=fx;

else

x2=x;f2=fx;

end

if abs(x2-x1)<tol, break,end

end

if i>100,disp('exeed 100 iterations'),end

fprintf('number of iterations = %g\n',i)

fprintf('root = %g\n',x)

else

disp('Two guessess do not bracket the root')

end

1