Originally Posted by

**Dream** Hello, I am trying to figure out how to use the bisection methode to do this problem and matlab, but I keep having problems with inputing my formula. Here is it below:

My formula: ln(x+1)+tan(2x) = 0

Here is my bisection method m-file:

function ww=bisect(f,a0,b0,tol)

%a and b are the end of the interval, c is the midpoint, n is iterations

%tol is our tolerence which is our stopping criteria

a=a0; b=b0;

sfb = sign(feval(f,b));

width = b-a;

n=0;

while width > tol

n=n+1;

width = width/2;

x = a + width;

sfx = sign(feval(f,x));

if sfx ==0

a = x; b = x; return

elseif sfx == sfb, b = x;

else a = x; end

end

c=0.5*(a+b);

ww=[a,b,c,n];

return

Could someone please tell me who to apply the above formula so that the bisection method is performed then I have to show the graph? I am new to matlab and it will not read the party in when I put in y = ln(x+1)+tan(2x) it keeps saying error.

Well the following seems to work for me:

Code:

»
»
»
» bisect('ff',0,10,0.001)
ans =
2.6831 2.6837 2.6834 14.0000
»

where ff.m is on the search path and defined the function:

Code:

function rv=ff(x)
rv=log(x+1)+tan(2*x);

But this is on a very old version of Matlab so this may no longer be the prefered format for passing a function as an argument to a function.

RonL