Advertisement
Pagoniusz

Untitled

Apr 28th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. a = 0;
  2. b = pi/2;
  3. x0_newt = ;
  4.  
  5. [xvect,xdif1,fx1,it_cnt1] = bisect(a,b, 1000,1e-4,@fun3);
  6. [xvect,xdif2,fx2,it_cnt2] = secant(a,b, 1000,1e-4,@fun3);
  7. [xvect,xdif3,fx3,it_cnt3] = newton(x0_newt, 1000,1e-4,@fun3,@fun3_poch);
  8.  
  9. % a)
  10. f_a = figure;
  11. hold on
  12. plot(1:it_cnt1, fx1, 'r-');
  13. plot(1:it_cnt2, fx2, 'g-');
  14. plot(1:it_cnt3, fx3, 'b-');
  15. legend('bisect', 'secant', 'newton');
  16. title('Przyblizenie w funkcji iteracji');
  17. hold off
  18.  
  19. % b)
  20. f_b = figure;
  21. hold on
  22. plot(1:it_cnt1, xdif1, 'r-');
  23. plot(1:it_cnt2, xdif2, 'g-');
  24. plot(1:it_cnt3, xdif3, 'b-');
  25. legend('bisect', 'secant', 'newton');
  26. title('Roznica w funkcji iteracji');
  27. hold off
  28.  
  29. % c)
  30. step = 0.01;
  31. max = 20;
  32. base_width = abs(b-a);
  33. widths = [];
  34. it_bis = [];
  35. it_sec = [];
  36. for i=0:step:max;
  37. widths = [widths, base_width+2*i];
  38. [xvect,xdif,fx,it_cnt] = bisect(a-i,b+i, 1000,1e-4,@fun3);
  39. it_bis = [it_bis , it_cnt];
  40. [xvect,xdif,fx,it_cnt] = secant(a-i,b+i, 1000,1e-4,@fun3);
  41. it_sec = [it_sec , it_cnt];
  42. end
  43.  
  44. f_c = figure;
  45. hold on
  46. plot(widths, it_bis, 'r-');
  47. plot(widths, it_sec, 'g-');
  48. legend('bisect', 'secant');
  49. title('Liczba iteracji w funkcji szerokosci przedzialu');
  50. hold off
  51.  
  52. pause
  53. close(f_a)
  54. close(f_b)
  55. close(f_c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement