Cod sursa(job #2258566)
| Utilizator | Data | 11 octombrie 2018 17:41:26 | |
|---|---|---|---|
| Problema | A+B | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
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
