Advertisement
Adytzu04

TO L1

May 31st, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.87 KB | None | 0 0
  1. clear
  2. clc
  3.  
  4. x0=input('Dati X0:')
  5. d=input('Dati pasul d:');
  6.  
  7.  
  8. x1=x0;
  9. f1=f(x1);
  10.  
  11. x2=x1+d;
  12. f2=f(x2);
  13.  
  14. if f1>f2
  15.     while f1>f2
  16.         d=2*d;
  17.         x1=x2;
  18.         x2=x1+d;
  19.         f1=f2;
  20.         f2=f(x2);
  21.        
  22.         x1
  23.         x2
  24.         f(x1)
  25.         f(x2)
  26.        
  27.        
  28.     end
  29.     xs=x1-d/2;
  30.     xd=x2;
  31.     xs
  32.     xd
  33. elseif f2>f1
  34.     d=-d;
  35.     x2=x1+d;
  36.     f2=f(x2);
  37.      
  38.     while f2>f1
  39.             d=2*d;
  40.             f1=f2;
  41.             x1=x2;
  42.             f1=f2;
  43.             x1=x1-d;
  44.             f2=f(x2);
  45.             x1
  46.             x2
  47.             f(x1)
  48.             f(x2)
  49.             return;
  50.     end
  51.    
  52. elseif (f2==f1)
  53.    
  54.       d=2*d;
  55.       x1=x2;
  56.       f1=f2;
  57.        x1
  58.        x2
  59.        f(x1)
  60.        f(x2)
  61.        return;
  62. end
  63.  
  64.     x1
  65.     x2
  66.     f(x1)
  67.     f(x2)
  68.     xs=x1-d/2;
  69.     xd=x2;
  70.     xs
  71.     xd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement