You are on page 1of 1

***f**

function [y]=f(x)
e=0.0025;
D=0.1;
Re=30000;
y=1.14-2*log10((e/D)+9.35./(Re*sqrt(x)))-(1./sqrt(x));

end

**biseccion***
function [sol,x,incr,iter]=biseccion(a,b,tol)%,maxiter)
format long;
fa=f(a);
fb=f(b);
if fa*fb>0
disp('la funcion debe tener signo distinto en los extremos del intervalo')
return
end
iter=1;
x=[];
incr=b-a;
while incr>tol %& iter<maxiter
c=(a+b)/2;
x=[x,c];
fc=f(x(iter));
%fc=feval(f,c);
if fc==0
a=c;b=c;
elseif fa*fc<0
b=c; fb=fc;
else
a=c; fa=fc;
end
incr=b-a;
iter=iter+1;
end
sol=c;
if incr>tol
disp('insuficientes iteracciones')
end
x

You might also like