Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear;
- clc;
- x0=input('Introduceti punctul de start: ');
- pas=input('Introduceti pasul de explorare: ');
- count=0;
- loop=1;
- flag=0;
- x1=x0;
- f1=p1(x1);
- finalflag=0;
- while loop==1
- x2=x1+pas;
- f2=p1(x2);
- count=count+1;
- if f2<f1
- x1=x2;
- f1=f2;
- else if f2>f1
- if count>=2 && flag ==0
- pas=pas/2;
- x1=x1-pas;
- finalflag=1;
- return;
- else
- if flag==0
- pas=-pas;
- flag=1;
- else
- x1=x1-pas;
- finalflag=1;
- end
- end
- else
- finalflag=1;
- end
- end
- if finalflag==1
- if x1 < x2
- xm=x1;
- xM=x2;
- else
- xM=x1;
- xm=x2;
- end
- loop = 0;
- end
- end
- xm
- xM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement