Pagini recente » Cod sursa (job #1705115) | Cod sursa (job #1561353) | Cod sursa (job #1731810) | Cod sursa (job #2174742) | Cod sursa (job #2258566)
function [ xaprox ] = MetBisectie( f,A,B,eps )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
a(1)=A;b(1)=B; x(1)=1/2*(a(1)+b(1));
N=floor(log2((B-A)/eps));
for k=2:N+1
if f(x(k-1))==0
x(k)=x(k-1);
break;
elseif f(a(k-1))*f(x(k-1))<0
a(k)=a(k-1); b(k)=x(k-1);
x(k)=1/2*(a(k-1)+b(k-1));
elseif f(a(k-1))*f(x(k-1))>0
a(k)=x(k-1); b(k)=b(k-1);
x(k)=1/2*(a(k-1)+b(k-1));
end
end
xaprox=x(k);
end