Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc; clear all;
- xdel(winsid());
- x=-2:0.01:1.5;
- f1=x.^2-2.*x+1;
- fh=scf(1);
- plot2d(x,f1);
- function [z]=f(x)
- z=x.^2-2.*x+1;
- endfunction
- a=2;
- b=1.5;
- e=0.001;
- L=b-a;
- q=(3-sqrt(5))/2;
- c=abs(b-a);
- while c>e
- fa=f(a);
- fb=f(b);
- if fa>fb then
- a=a+(1-q).*(b-a)
- fa=f(a);
- elseif fa<fb then
- b=a+q.*(b-a)
- fb=f(b);
- elseif fa==fb then
- a=a+(1-q).*(b-a)
- fa=f(a)
- b=a+q.*(b-a)
- fb=f(b)
- end
- c=abs(b-a);
- end
- if c<e then
- printf('Wynik jest dobry %f<%f',c,e);
- else
- printf('Wynik jest zły');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement