You are on page 1of 5

Submission Date: 12.11.

2012

Middle East Technical University Department of Mechanical Engineering ME 310 - Numerical Methods Group #9 Project Assignment I Report
Salih Can amdere (1744606)* mer Refet aylan (1744648) Eda Daldiken (1743558)
*Group Leader

Introduction In this programming project assignment, it is asked to find the roots of a non-linear function by using the False Position Method in MATLAB. As known, False Position method (a.k.a. Regula Falsi Method) is a numerical method which is mostly used in root finding applications. In numerical analysis, false position method is used as a combination of a bisection method and secant method and it can be shown graphically as;

Fig. 1. Graph of the f(x) Initial boundaries of the method are shown as a & b with subscripts increasing with the iteration number from 0 to 2 in the figure above. The initial conditions are chosen such that f(a0)*f(b0)<0. This condition comes from the results of the mean value theorem which asserts that between the function values with opposite signs, there's a root in between. (1) The root of the secant lines in each iteration can be calculated by the above formula. Iteration number is indicated with subscript k.

If we show the above equation in line format, with given boundary conditions ( both a, b, and their values under the function) the construct a line passes through those points and the equation of the line becomes; (2) To obtain the equation (1), we now choose c to be the root of this line and setting y=0 in equation (2) to get the below equation; (3) Therefore, solving the equation (3) gives the equation (1) for c. Having defined the mathematical and geometrical aspect of the method, the programming part of the mathematical model created can be done *** As it is mentioned, the programming project is about finding the roots of a nonlinear polynomial structured function. In specific, the function is; f(x)= x^10-1 Graph of the function which is obtained by using MATLAB is as follows;

Fig. 2. Graph of the given sample function The above graph is obtained by using the following MATLAB code; >> ezplot('x^10 1', [-2,2]);

From the graphical interpretation, it is seen that, the function has two real roots. By using mathematical programming modules' embedded root finding functions, it can be identified that the given polynomial has 8 complex roots. In the programming assignment definition, it is said that the sample function test to be done with 0 to be the initial lower boundary and 1.3 to be the initial upper boundary. So, in the programming part, the value of a=0 & b=1.3 are chosen by default. Programming Part (MATLAB R2009b Code)
%STUDENT NAME & SURNAME: SALIH CAN CAMDERE %STUDENT ID: 1744606 %PROJECT ASSIGNMENT #1 %DATE: 12.11.2012 %MATLAB VERSION: 7.9.0 (R2009b) %-------------------------------------------------------------------------function e174460() % Name of the main function clear all; % The command that clears all the variables clc; % Clearing command window close all; % Closing of all the figures opened format long; % Format definition of the function syms x; %------------variables:---------------------------------------------------func = input('Enter the desired function : ' ); %Input function definition ezplot(func); %Input function graph drawing grid on; % Open grid on function graph func = inline(func); %String / inline conversion a = input('Enter lower bound: '); % Initializing the lower boundary b = input('Enter upper bound: '); % Initializing the upper boundary tol = input('Enter tolerance: '); % Entering the desired error to terminate the procedure ea = 1; % Set high for 1st pass through while-loop ia = 0; % Dummy variable to count the number of iterations in which a stays unmoved ib = 0; % Dummy variable to count the number of iterations in which b stays unmoved c_old = 0; %Initial c value by default fa = func(a); fb = func(b); k = 0; while ea > tol k = k+1; c = a - fa*(b-a)/(fb-fa); fc = func(c); ea=100*abs((c-c_old)/c); %Error calculation algorithm definition if fa*fc < 0; b = c; fb = fc; ib = 0; % Right side counter reset ia = ia+1; % Left side counter increment if ia > 1; fa=fa/2; %Modified false position addition for left-end end else

a = c; fa = fc; ia = 0; % Left side counter reset ib = ib+1; % Right side counter increment if ib > 1; fb=fb/2; %Modified false position addition for right-end end end c_old = c; end c_answer = c; number_of_iterations = k; %-------------------------------------------------------------------------%-------------------------------------------------------------------------%Command Window Output disp('NAME SURNAME : SALIH CAN CAMDERE'); disp('ID : 1744606'); disp('GROUP NO : 9') disp('PROJECT ASSIGNMENT 1') disp('SUBMISSION DATE: 12.11.2012'); disp(' '); disp('False Position Method'); disp(['Number of Iterations : ' num2str(number_of_iterations)]); disp(['Root : ' num2str(c_answer)]); disp(['Approximate Error (%) : ' num2str(ea)]); disp(' '); %-------------------------------------------------------------------------end %--------------------------------------------------------------------------

As a result of the given dataset which is preset at the project as lower limit 0, upper limit 1.3 and error tolerance as 0.01, following output is obtained;
>> Enter the desired function : x^10-1 Enter lower bound: 0 Enter upper bound: 1.3 Enter tolerance: 0.01 NAME SURNAME : SALIH CAN CAMDERE ID : 1744606 GROUP NO : 9 PROJECT ASSIGNMENT 1 SUBMISSION DATE: 12.11.2012 False Position Method Number of Iterations Root Approximate Error (%) >> : 12 : 1 : 0.0011643

Discussion & Comments Plot of the function for default given polynomial gives vague result because of the string/inline clash. However, in the figure presented above, code gave the correct result. This situtation most probably is caused by the grid issues or default function domain which is [-2pi, 2pi]. The modified algorithm is, we think, works well since the example function stays steady in large intervals and its increment/decrement characteristics change dramatically in relatively smaller intervals. In the algorithm we used previously without using the modified false position algorithm finds the root more than 20 iterations and this also shows that modified algorithm is more efficient to find the root.

References [1] J.A. Ford (1995). Improved Algorithms of Illinois-type for the Numerical Solution of Nonlinear Equations.Technical Report CSM-257. University of Essex Press. [2] Richard L. Burden, J. Douglas Faires (2000).Numerical Analysis, 7th ed. Brooks/Cole. ISBN 0-534-38216-9. [3] L.E. Sigler (2002). Fibonacci's Liber Abaci, Leonardo Pisano's Book of Calculation. Springer-Verlag, New York. ISBN 0-387-40737-5. [4] Dowell, M.; Jarratt, P. (1971). "A modified regula falsi method for computing the root of an equation". BIT 11(2): 168174. DOI:10.1007/BF01934364.

You might also like