Wednesday, 29 June 2011

Numerical Methods Using MATLAB - Method of False Position

In this post, we solve Algebraic Equations using Regular Falsi Method, also known as Method of False Position. 

Regula Falsi Method:
         Consider the equation f(x)=0. Let a and b be two points such that f(a)<0 and f(b)>0. The function f(x) cuts x-axis at some point between (a,f(a)) and (b,f(b)).  The equation of chord joining the two points is given by,


         The point where the chord cuts the x-axis gives an approximate value root of f(x)=0. Hence, we substitute y=0 in the above equation to get an expression for x, as follows:


          This value of x1 gives an approximate value of root of the equation f(x)=0. Substitute x1 in f(x) and find f(x1).

IF f(x1) > 0

        Thus, we get a sequence of roots x1,x2,..... The sequence converge to required root with required accuracy.

Source Code :
% Function that calculates approximate solution using Regula Falsi (or) False Position Method
function    RegFalsiFunc(co,deg,rang)
     % x=a --> f(x)<0
     % x=b --> f(x)>0
     a = rang(1);
     b = rang(2);

     % initialize previous var to 0

     % infinite loop
     while ( 1 )
            % find fa,fb,fx1 substituting a,b in f(x)
            fa = SubFunc(deg,co,a);
            fb = SubFunc(deg,co,b);
             % find x1 from fa,fb,a,b
             x1 = ((a*fb)-(b*fa))/(fb-fa);

            % find fx1 substituting x1 in f(x)
            fx1 = SubFunc(deg,co,x1);
            % if fx1 is negative replace a with x1
            if (fa*fx1)>0      a=x1;
            % else replace b with x1
            else    b=x1;
            % end of if....else
            % end the loop when required accuracy is achieved
            if abs(abs(x1)-abs(prev)) < 0.000001
            % end of if
            prev = x1;
      % end of while
% end of function


Post a Comment

தங்களது கருத்துக்களை இங்கே வெளியிடவும்...


Twitter Delicious Facebook Digg Stumbleupon Favorites More