Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Metoda Fibonacciego:
- clc; clear all;
- xdel(winsid());
- x=-2:0.01:1.5;
- f1=x.^2-2.*x+1;
- fh=scf(1);
- plot2d(x,f1);
- fh1=gce();
- fh1.children.foreground=color('scilab red2');
- fh1.children.thickness=2;
- fh1.children.line_style=7;
- ah=gca();
- ah.grid=[1 1];
- ah.grid_style=[9 9];
- title('$Wykres funkcji$');
- xlabel('$x$');
- ylabel('$y$');
- ah.x_label.font_size=4.5;
- ah.y_label.font_size=4.5;
- ah.title.font_size=5;
- lh=legend('$f_1=x^2-2x+1$');
- lh.legend_location="in_upper_right";
- lh.font_size=3;
- function [z]=f(x)
- z=x.^2-2.*x+1;
- endfunction
- a=-2;
- b=1.5;
- e=0.001;
- fa=f(a);
- fb=f(b);
- L=b-a;
- Fn=[1 1];
- n=2;
- while 1
- n=n+1;
- Fn(n)=Fn(n-1)+Fn(n-2);
- if Fn(n)>(1+2*e)*(L/e);
- break;
- end;
- end
- Fn(n+1)=Fn(n-1)+Fn(n-2);
- k=1;
- while(k<n)
- r=1-((Fn(n-k+1))/(Fn(n-k+2)));
- fa=f(a);
- fb=f(b);
- if fa>fb then
- a=a+r*(b-a);
- fa=f(a);
- elseif fa<fb then
- b=a+(1-r)*(b-a);
- fb=f(b);
- elseif fa==fb then
- a=a+r*(b-a);
- fa=f(a)
- b=a+(1-r)*(b-a);
- fb=f(b)
- end
- k=k+1;
- plot2d(a,f(a),style=-5); ea=gce(); ea.children.mark_foreground=5; // część kodu do zad 2
- plot2d(b,f(b),style=-5); eb=gce(); eb.children.mark_foreground=5; //
- pause //
- delete(ea); //
- delete(eb); //
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement