Advertisement
Bkmz

Untitled

Apr 25th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.21 KB | None | 0 0
  1. % hold off
  2. Epsilo = 0.005
  3. MaxSteps = 200
  4. step = 0.1;
  5. v = 4
  6. H = 0.0001;
  7.  
  8. % [x,y] = meshgrid(-v:step:v, -v:step:v);
  9. [x,y] = meshgrid(-v:step:v, -v:step:v);
  10.  
  11. % func =  sym('x1^2 + y1^2')
  12. func = sym('(1-x1)^2 + 100*(y1-x1^2)^2');
  13. % func = sym('2*x1^2 + y1^2 + x1*y1')
  14. % func = sym('-2*x1^2 - y1^2 + x1*y1')
  15. syms x1 y1
  16. % func = sym('sin(((1/2)*x1^2)-((1/4)*y1^2) + 3)*cos(2*x1 + 1 - exp(y1))');
  17. func_hl = matlabFunction(func);
  18.  
  19. derivateX = diff(func, x1);
  20. derivateX = matlabFunction(derivateX);
  21.  
  22. derivateY = diff(func, y1);
  23. derivateY = matlabFunction(derivateY);
  24.  
  25. z = func_hl(x,y);
  26.  
  27. stX = -0.8;
  28. stY = -1.5;
  29. % stX = -2;
  30. % stY = -0.25;
  31.  
  32. hold on;
  33. contour(x,y,z, 32);
  34. % surfc(x,y,z);
  35. % clabel(C, h);    % Отображение меток  на линиях уровня
  36. % quiver(x,y,gx,gy);
  37.  
  38.  
  39. X = stX, Y=stY
  40. steps = 0
  41. plot(X,Y,'+');
  42. % break
  43.  
  44. for i=1:MaxSteps
  45.     derX = derivateX(X, Y);
  46.     derY = derivateY(X, Y);
  47.    
  48.     derX = derX * H;
  49.     derY = derY * H;
  50.    
  51.      
  52.      X = X - derX;
  53.      Y = Y - derY;
  54.      
  55.      plot(X,Y,'x');
  56.      steps = steps + 1;
  57.      if sqrt(derX^2 + derY^2) <= Epsilo;
  58.          break
  59.      end
  60.      
  61. end
  62.  
  63.  
  64. plot(X,Y,'r*');
  65. X
  66. Y
  67.  
  68. % hold on
  69. hold off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement