Posted By:
31 Mar, 2013 7:47 am PDT

Use fzero and false-position to find root of a function in Matlab

I have a function f = x^2|sin(x)|-4.
I want to use fzero function to find to root. My initial guess x0 = 0.5.
How can I use false-position method to find the root. my guessing interval is [0,4].

The root should be 3.478509

Attachment:None


%function
f = @(x) x.^2.*abs(sin(x))-4;

False Position Method

%------------------------
xl=0; xu=4; xr=0; fxr=f(xr);
while abs(fxr)>1e-10
    xr = xu-( f(xu)*(xl-xu) )/( f(xl)-f(xu) ); %compute xr
    fxr = f(xr);
    if fxr*f(xl)<0 %root is left of xr
        xu=xr;
    else %root is right of xr
        xl=xr;
    end
end
root_false_position = xr


%%% Using fzero
%------------------------
root_fzero = fzero(f,0.5)

 Please watch video for details

Attachment: fzero_falsePosition.m
Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud