False position method in MATLAB

False position(also called the linear interpolation method) is another well-known bracket-ing method. It is very similar to bisection with the exception that it uses a different strategy
to come up with its new root estimate. Rather than bisecting the interval, it locates the root
by joining f(xl)and f(xu)with a straight line.The intersection of this line with
the xaxis represents an improved estimate of the root. Thus, the shape of the function in-fluences the new root estimate.[1]

%Author: Muhammad Awais
%UET Lahore, Electrical Engineering
%fb/awais12506

function [xr,iteration]=FalsePosition(xl,xu,f,e)
%Find Root of a equation by method of BiSection
%Input: Lower Limit, Upper Limit, Function, Error Tolerance
%Please Insert f as f=@(x)x.^2+9*x+3
%Output: Root of the equation with given precison
%Exception: Give error if Equation is not convergent or roots are dont give
%postive and negative values of the function

iteration=0;     %To see how many iterations, equation took to solve
xr=xl;
error=1;
if  (f(xl)*f(xu)>0)
    disp('Interval have some error')

else
    fprintf('Itr     XR')
     while ( abs(error) > abs(e) ||iteration<=1000 )
        iteration=iteration+1;
        xrOld=xr;
        xr=xu-( (f(xu)*(xl-xu)) /(f(xl)-f(xu)));   %Mid point
        xrNew=xr;
        if f(xl)*f(xr)<0   %if f(xm) is neg, equate xu with xm
            xu=xr;
        else if f(xl)*f(xr)>0 %if f(xm) is pos, equate xl with xm
            xl=xr;
            else            %it means xm is our root
            break
            end
        error=(xrNew-xrOld)/xrNew;   %Error

        end

    end

end
end

Output:



References:
[1] Applied Numerical Methods with MATLAB for Engineers and Scientists by Steven C. Chapra
Berger Chair in Computing and Engineering
Tufts University

1 comment:

  1. Uetian Blogger: False Position Method In Matlab >>>>> Download Now

    >>>>> Download Full

    Uetian Blogger: False Position Method In Matlab >>>>> Download LINK

    >>>>> Download Now

    Uetian Blogger: False Position Method In Matlab >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete

Thank you for your response.