Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Metoda Fibonacciego:
  2.  
  3. clc; clear all;
  4. xdel(winsid());
  5. x=-2:0.01:1.5;
  6. f1=x.^2-2.*x+1;
  7. fh=scf(1);
  8. plot2d(x,f1);
  9.  
  10. fh1=gce();
  11. fh1.children.foreground=color('scilab red2');
  12. fh1.children.thickness=2;
  13. fh1.children.line_style=7;
  14.  
  15. ah=gca();
  16. ah.grid=[1 1];
  17. ah.grid_style=[9 9];
  18. title('$Wykres funkcji$');
  19. xlabel('$x$');
  20. ylabel('$y$');
  21. ah.x_label.font_size=4.5;
  22. ah.y_label.font_size=4.5;
  23. ah.title.font_size=5;
  24.  
  25. lh=legend('$f_1=x^2-2x+1$');
  26. lh.legend_location="in_upper_right";
  27. lh.font_size=3;
  28.  
  29. function [z]=f(x)
  30. z=x.^2-2.*x+1;
  31. endfunction
  32.  
  33. a=-2;
  34. b=1.5;
  35. e=0.001;
  36.  
  37. fa=f(a);
  38. fb=f(b);
  39. L=b-a;
  40. Fn=[1 1];
  41. n=2;
  42. while 1
  43. n=n+1;
  44. Fn(n)=Fn(n-1)+Fn(n-2);
  45. if Fn(n)>(1+2*e)*(L/e);
  46. break;
  47. end;
  48. end
  49. Fn(n+1)=Fn(n-1)+Fn(n-2);
  50. k=1;
  51.  
  52. while(k<n)
  53. r=1-((Fn(n-k+1))/(Fn(n-k+2)));
  54. fa=f(a);
  55. fb=f(b);
  56. if fa>fb then
  57. a=a+r*(b-a);
  58. fa=f(a);
  59. elseif fa<fb then
  60. b=a+(1-r)*(b-a);
  61. fb=f(b);
  62. elseif fa==fb then
  63. a=a+r*(b-a);
  64. fa=f(a)
  65. b=a+(1-r)*(b-a);
  66. fb=f(b)
  67. end
  68. k=k+1;
  69. plot2d(a,f(a),style=-5); ea=gce(); ea.children.mark_foreground=5; // część kodu do zad 2
  70. plot2d(b,f(b),style=-5); eb=gce(); eb.children.mark_foreground=5; //
  71. pause //
  72. delete(ea); //
  73. delete(eb); //
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement