% cel: x = cos(x) mikor? % ehelyett: cos(x) - x = 0 megoldasat keressuk % [0,1] intervallumon a = 0 b = 1 x = (a+b)/2 f1(a) f1(b) f1(x) function y = f1(x) y = cos(x) - x; endfunction hiba = (b-a)/2 while hiba > 0.1 if (f1(a) * f1(x) < 0) % [a,x] intervallumon elojelvaltas % [a,x] intervallumban van a gyok b = x else % [x,b] intervallumon van elojelvaltas, % [x,b] intervallumon folytatjuk a = x endif x = (a+b)/2 f1(x) hiba = hiba/2 endwhile t = 0:0.05:1; f = f1(t); plot(t,f,t,t*0)