Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = 0;
- b = pi/2;
- x0_newt = ;
- [xvect,xdif1,fx1,it_cnt1] = bisect(a,b, 1000,1e-4,@fun3);
- [xvect,xdif2,fx2,it_cnt2] = secant(a,b, 1000,1e-4,@fun3);
- [xvect,xdif3,fx3,it_cnt3] = newton(x0_newt, 1000,1e-4,@fun3,@fun3_poch);
- % a)
- f_a = figure;
- hold on
- plot(1:it_cnt1, fx1, 'r-');
- plot(1:it_cnt2, fx2, 'g-');
- plot(1:it_cnt3, fx3, 'b-');
- legend('bisect', 'secant', 'newton');
- title('Przyblizenie w funkcji iteracji');
- hold off
- % b)
- f_b = figure;
- hold on
- plot(1:it_cnt1, xdif1, 'r-');
- plot(1:it_cnt2, xdif2, 'g-');
- plot(1:it_cnt3, xdif3, 'b-');
- legend('bisect', 'secant', 'newton');
- title('Roznica w funkcji iteracji');
- hold off
- % c)
- step = 0.01;
- max = 20;
- base_width = abs(b-a);
- widths = [];
- it_bis = [];
- it_sec = [];
- for i=0:step:max;
- widths = [widths, base_width+2*i];
- [xvect,xdif,fx,it_cnt] = bisect(a-i,b+i, 1000,1e-4,@fun3);
- it_bis = [it_bis , it_cnt];
- [xvect,xdif,fx,it_cnt] = secant(a-i,b+i, 1000,1e-4,@fun3);
- it_sec = [it_sec , it_cnt];
- end
- f_c = figure;
- hold on
- plot(widths, it_bis, 'r-');
- plot(widths, it_sec, 'g-');
- legend('bisect', 'secant');
- title('Liczba iteracji w funkcji szerokosci przedzialu');
- hold off
- pause
- close(f_a)
- close(f_b)
- close(f_c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement