Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. fun = @(x) 4*x(1)-x(2)^2-12;
  2.  
  3. h1(x1,x2) = 25 - x1^2 - x2^2;
  4. g2(x1,x2) = 10*x1 - x1^2 + 10*x2 - x2^2 - 34;
  5. g3(x1,x2) = x1;
  6. g4(x1,x2) = x2;
  7.  
  8.  
  9. % draw the function
  10.  
  11. xval = 0:0.1:7;
  12. yval = 0:0.1:7;
  13. funval = zeros(numel(xval));
  14.  
  15. i = 1;
  16. while( i <= length(xval) )
  17. j = 1;
  18. while( j <= length(yval) )
  19. funval(i,j) = fun([xval(i), yval(j)]);
  20. j = j + 1;
  21. end
  22.  
  23. end
  24. i = i + 1;
  25. end
  26.  
  27. plot(x(1), x(2), 'r*'); % punkturinn
  28.  
  29.  
  30. hold on;
  31. % bæti við g2
  32. fimplicit(@(x1,x2) -x1^2 + 10*x1 - x2^2 + 10*x2 - 34, [0 7 0 7]);
  33.  
  34.  
  35. %plotta contour
  36. contour(xval, yval,funval);
  37.  
  38.  
  39. % bæti við jöfnunni h1
  40. %contour(h1val, yval,funval);
  41. xlim([0,7]);
  42. ylim([0,7]);
  43. circle(0,0,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement