Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
2,968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. clear;
  2. clc;
  3.  
  4. x0=input('Introduceti punctul de start: ');
  5. pas=input('Introduceti pasul de explorare: ');
  6.  
  7. count=0;
  8. loop=1;
  9. flag=0;
  10. x1=x0;
  11. f1=p1(x1);
  12. finalflag=0;
  13. while loop==1
  14. x2=x1+pas;
  15. f2=p1(x2);
  16. count=count+1;
  17. if f2<f1
  18. x1=x2;
  19. f1=f2;
  20. else if f2>f1
  21. if count>=2 && flag ==0
  22. pas=pas/2;
  23. x1=x1-pas;
  24. finalflag=1;
  25. return;
  26. else
  27. if flag==0
  28. pas=-pas;
  29. flag=1;
  30. else
  31. x1=x1-pas;
  32. finalflag=1;
  33. end
  34. end
  35. else
  36. finalflag=1;
  37. end
  38. end
  39. if finalflag==1
  40. if x1 < x2
  41. xm=x1;
  42. xM=x2;
  43. else
  44. xM=x1;
  45. xm=x2;
  46. end
  47. loop = 0;
  48. end
  49. end
  50. xm
  51. xM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement